-1

Hi I try to send mail to registred user.

This is my code :

   function email($to, $subject, $body, $from){
            require'PHPMailer-master/PHPMailerAutoload.php';

            define('GUSER', '[email protected]');
            define('GPWD', 'pass');

            $mail = new PHPMailer();  // create a new object
            $mail->IsSMTP(); // enable SMTP
            $mail->SMTPDebug = 0;  // debugging: 1 = errors and messages, 2 = messages only
            $mail->SMTPAuth = true;  // authentication enabled
            $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
            $mail->Host = 'smtp.gmail.com';
            $mail->Port = 465; 
            $mail->Username = GUSER;  
            $mail->Password = GPWD;     
            $mail->SetFrom($from);
            $mail->Subject = $subject;
            $mail->Body = $body;
            $mail->AddAddress($to);
        }
function register_user($register_data){
        array_walk($register_data, 'array_sanitize');
        $register_data['password'] = md5($register_data['password']);
            $fields = '`' . implode ('`, `', array_keys($register_data)) . '`';
            $data = '\'' . implode('\',\'',$register_data) . '\'';
        mysql_query("INSERT INTO `users` ($fields) VALUES ($data)");
        email($register_data['email'],  'Aktivirajte svoj korisnički račun', "Zdravo".$register_data['username'].",\n\n da bi aktivirao svoj korisnički račun odi na dolje navedeni link:\n\n http://localhost/New%20folder%20(4)/index.php/activate.php?email=".$register_data['email']."&email_code=".$register_data['email_code']."\n\n CroVision");
    }

There is no errors in my code but still can't send mail.

Thanks

3
  • 1
    Did you try enabling debug? Commented Feb 14, 2015 at 17:41
  • @RowlandShaw still nothing
    – CroStorm
    Commented Feb 14, 2015 at 17:44
  • 1
    What's the result status of the $mail->Send() call?
    – mario
    Commented Feb 14, 2015 at 17:48

3 Answers 3

1

I hope you are working on Linux. If that is the case, please check your /var/log/mail.log or /var/log/maillog depends on the linux distro. The issue can be the server is bouncing your email for different reassons.

Note: have you install sendmail or postfix?

If this is a windows environment, i am so sorry, i can't help you.

Good luck

0
0

change $mail->SMTPDebug = 0; to $mail->SMTPDebug = 1; so it will display you the errors.

Also confirm whether you are passing the variables as email address.

If you are with any hosting account, then sometimes there is a chance that you would not be able to send using SMTP.

If you are using localhost, try opening ssl in php.ini file. It might solve your problem if you dont see any error.

1
  • Try port no. 587 or try using hardcoded email instead of passing through $to. If not check spam emails Commented Feb 14, 2015 at 17:51
0

You do not supply any value for the $from parameter in the call to email()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.