簡體   English   中英

使用 PHPMailer 從 Gsuite 郵件別名發送郵件

[英]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_USERNAMEalias@example.com作為MAIL_ADDRESS ,但這也不起作用。

結果

沒有報錯,頁面顯示“成功”郵件; 但是,當我訪問我的用戶時,實際上沒有發送/接收郵件。 由於 GSuite 顯然將所有別名郵件路由到我的標准地址,我應該會看到它。

如果我遺漏了什么,請告訴我,謝謝!

@Synchro 的解決方案有效,為方便起見,這里是一個簡短的分步解決方案:

  1. 在您的計算機上,打開 Gmail。
  2. 在右上角,單擊設置設置,然后單擊查看所有設置。
  3. 單擊帳戶和導入或帳戶選項卡。
  4. 在“發送郵件”部分中,單擊添加另一個電子郵件地址。
  5. 輸入您的姓名和要發送的地址。
  6. 單擊下一步,然后單擊發送驗證。
  7. 單擊添加帳戶

了解更多: https : //support.google.com/mail/answer/22370?hl=en

現在一切都應該正常工作:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM