Reputation: 373
I'm trying to send a message from a script on a site, using SMTP. I can successfully read the mail on my personal email, although my work email does not receive it. I think it might be bouncing.
In the Google admin panel, I have added test.domain.com as an alias for domain.com.
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->SMTPDebug = 2;
$mail->From = "[email protected]";
$mail->FromName = "No-Reply @ Domain";
$to = '[email protected], [email protected]';
$mail->AddAddress('[email protected]');
$mail->AddAddress('[email protected]');
$mail->AddReplyTo($mail->From, $mail->FromName);
$mail->WordWrap = 80; // set word wrap to 50 characters
$mail->IsHTML(false); // set email format to HTML
$mail->Subject = $subject[PAGE];
$mail->Body = $body;
if ( $mail->Send() )
{
header('location: '.$_SERVER['REQUEST_URI'].'?sent1');
exit;
}
else
{
$errors[] = 'Sorry, your message could not be sent, '.$mail->ErrorInfo;
}
I have created an MX record for test.domain.com as well as an SMTP relay service in Google Admin, as well as allowing per-user outbound gateways (Allow users to send mail through an external SMTP server when configuring a "from" address hosted outside your email domains).
Upvotes: 0
Views: 1415
Reputation: 896
When we set up PHP mailer we need to add the credentials of SMTP mail Server in it.In you code example you skipped those lines and it is ncessary to send an email
mail->Host = "smtp.yourmail.com"; // Your SMTP server
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->SMTPSecure = 'tls'; //SMTP secure type like ssl/tls
$mail->Username = "[email protected]"; // SMTP username
$mail->Password = "password"; // SMTP password
$mail->From = "[email protected]"; // SMTP username
Please try with proper credentials on the top after initialisation of object $mail
Upvotes: 1