Reputation: 167
I have an issue with PHPMailer. I want to send an e-mail form myself to myself, when a certain form is filled on my website (with the informations of the form in it), but I can't get it to work. PHP doesn't send any error (I made sure it's enabled), but with SMTPDebug, I get this:
2015-02-12 07:35:58 CLIENT -> SERVER: EHLO localhost
2015-02-12 07:35:58 CLIENT -> SERVER: MAIL FROM:
2015-02-12 07:35:58 CLIENT -> SERVER: RCPT TO:
2015-02-12 07:35:58 SMTP ERROR: RCPT TO command failed: 550 5.7.1 ... Relaying denied. Proper authentication required.
2015-02-12 07:35:58 CLIENT -> SERVER: QUIT
2015-02-12 07:35:58 SMTP Error: The following recipients failed: [email protected]
Here's the code sample:
require("PHPMailer-master/PHPMailerAutoload.php");
$mail = new phpmailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->Host = "smtp.server.com"; //Mod
$mail->From = "[email protected]"; //Mod
$mail->FromName = "Automatic e-mail, no reply";
$mail->AddAddress("[email protected]"); //Mod
$mail->Subject = "A student forgot his password";
$mail->Body = $class.'\r\n'.$fname.' '.$lname;
$mail->WordWrap = 70;
if(!$mail->Send())
$sent = false;
else
$sent = true;
(The //Mod
at the end of a line indicates that I modified the data for privacy reasons.)
Now I've read some people fixed this by commenting this line:
mail->IsSMTP();
But I only get another error when I do that:
Could not instantiate mail function
Which seems quite logical to me.
Upvotes: 0
Views: 3584
Reputation: 727
The server requires a valid authenticated user, you need to add authorization credentials. Of course change the values of Username and Password for valid authorization credentials in your SMTP server.
$mail->SMTPAuth = true;
$mail->Username = "yourauthorizeduser"; // It could be [email protected]"
$mail->Password = "v3rys3cr3t";
Upvotes: 4