[英]Send mail from Gsuite mail alias with PHPMailer
我正在嘗試在我的網站上使用 PHPMailer 將郵件作為聯系表單的一部分發送。 我想使用contact@example.com
而不是standard_email@example.com
來發送郵件,以進行過濾和安全。 我的郵件由 GSuite(以前稱為 Google Apps)處理,設置如下:
standard_email@example.com
contact@example.com --> standard_email@example.com
在 PHPMailer 配置中使用standard_email@example.com
時,我的發送工作正常,但是當我嘗試使用別名發送時,它不起作用。 這對 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);
}
我還嘗試使用standard_email@example.com
作為SMTP_USERNAME
和alias@example.com
作為MAIL_ADDRESS
,但這也不起作用。
沒有報錯,頁面顯示“成功”郵件; 但是,當我訪問我的用戶時,實際上沒有發送/接收郵件。 由於 GSuite 顯然將所有別名郵件路由到我的標准地址,我應該會看到它。
如果我遺漏了什么,請告訴我,謝謝!
@Synchro 的解決方案有效,為方便起見,這里是一個簡短的分步解決方案:
了解更多: https : //support.google.com/mail/answer/22370?hl=en
現在一切都應該正常工作:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.