[英]Send mail from Gsuite mail alias with PHPMailer
I'm trying to use PHPMailer on my website to send mail as part of a contact form.我正在尝试在我的网站上使用 PHPMailer 将邮件作为联系表单的一部分发送。 I would like to use
contact@example.com
instead of standard_email@example.com
to send mail, for filtering and security.我想使用
contact@example.com
而不是standard_email@example.com
来发送邮件,以进行过滤和安全。 My mail is handled by GSuite (formerly called Google Apps) and is setup like below:我的邮件由 GSuite(以前称为 Google Apps)处理,设置如下:
standard_email@example.com
standard_email@example.com
contact@example.com --> standard_email@example.com
contact@example.com --> standard_email@example.com
I have sending working perfectly when using standard_email@example.com
in the PHPMailer configuration, but when I try to send using the alias it does not work.在 PHPMailer 配置中使用
standard_email@example.com
时,我的发送工作正常,但是当我尝试使用别名发送时,它不起作用。 Is this not possible with GSuite aliases?这对 GSuite 别名是不可能的吗?
define("SMTP_HOST", "smtp.gmail.com");
define("MAIL_ADDRESS", "alias@example.com");
define("SMTP_USERNAME", "alias@example.com");
...
//Configure SMTP authentication
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = SMTP_HOST;
$mail->SMTPAuth = true;
$mail->Username = SMTP_USERNAME;
$mail->Password = SMTP_PASSWORD;
$mail->SMTPSecure = "tls";
$mail->Port = SMTP_PORT;
//Set email headers
$mail->setFrom(MAIL_ADDRESS, "Contact Us Submission");
$mail->addAddress(MAIL_ADDRESS, "Contact Us Submission");
$mail->addReplyTo($form_email, $form_name);
$mail->isHTML(true);
//Set email content
$mail->Subject = htmlspecialchars($form_subject);
$mail->Body = htmlspecialchars($form_comments);
$mail->AltBody = htmlspecialchars($form_comments);
//Attempt to send the message and display the results to the user
if ($mail->send() == false) {
return new MailResponse(1, "Message could not be sent", $contactSubmission);
} else {
return new MailResponse(0, "Message sent successfully", $contactSubmission);
}
I've also tried using standard_email@example.com
as the SMTP_USERNAME
and alias@example.com
as the MAIL_ADDRESS
, but that didn't work either.我还尝试使用
standard_email@example.com
作为SMTP_USERNAME
和alias@example.com
作为MAIL_ADDRESS
,但这也不起作用。
There are no reported errors, and the page displays the "success" mail message;没有报错,页面显示“成功”邮件; however, no mail is actually sent/received when I visit my user.
但是,当我访问我的用户时,实际上没有发送/接收邮件。 Since GSuite apparently routes all of the alias mail to my standard address, I should be seeing it.
由于 GSuite 显然将所有别名邮件路由到我的标准地址,我应该会看到它。
Let me know if I'm missing something, and thanks!如果我遗漏了什么,请告诉我,谢谢!
The solution from @Synchro works and for convenience here is a short step by step solution: @Synchro 的解决方案有效,为方便起见,这里是一个简短的分步解决方案:
Learn more: https://support.google.com/mail/answer/22370?hl=en了解更多: https : //support.google.com/mail/answer/22370?hl=en
Everything should be working now :)现在一切都应该正常工作:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.