user695575
user695575

Reputation: 127

Not getting email using PHP

I want to send a conformation email using php code. I have tried all solutions such as mail() and phpmailer but nothing is working. Here is my code for mail()

ini_set(sendmail_from, "[email protected]" );
ini_set(SMTP, "aspmx2.googlemail.com" );
ini_set(smtp_port, 25 );
$username = "xyz";
 $password = "password";
$to=$email;
$subject="Activate you account"; 
$message="
Hello $fullname, \n \n
    ";
$headers="From: xyz@ domainname.net";
 mail($to, $subject, $message, $headers);
die ("You have been registerd. Check you email to activate your account!");

I am getting “You have been registered. Check you email to activate your account” message on the page, but I am not getting an email.

I tried without ini_set() but it is still not working. I also have set SMTP and port in php.ini file but it is still not working.

Please help!! Thanks

Upvotes: 1

Views: 186

Answers (3)

Nikola Sivkov
Nikola Sivkov

Reputation: 2852

Try sending e-mails using PHPmailer i have heard lots of great things about it.

sample of PHPMailer config

$mail->Mailer = "smtp";  
$mail->Host = "ssl://smtp.gmail.com";  
$mail->Port = 465;  
$mail->SMTPAuth = true; // turn on SMTP authentication  
$mail->Username = "[email protected]"; // SMTP username  
$mail->Password = "password"; // SMTP password 

Upvotes: 0

Marc B
Marc B

Reputation: 360762

You're not actually setting the username/password for the mail() call. All you're doing is setting some variables, and then not using those variables in any way for the mail. So your attempt to send mail through Google fails, because you're not authenticating.

But as other answers have said, don't use the built-in mail() function. Use PHPMailer or Swiftmailer instead. They're far easier to use, handle all the ugly stuff of doing file attachments and multi-part MIME mail, and do it all behind a nice OOP interface.

Upvotes: 4

tylerl
tylerl

Reputation: 30867

To points here:

You're calling mail without checking the return code -- which means that you know that you're attempting to send a message, but you have no idea whether it succeeds. Which isn't helpful for debugging.

And second, Gmail requires an encrypted connection before they will allow you to authenticate. And a standard SMTP connection isn't encrypted.

Upvotes: 1

Related Questions