[英]How to change the “from” header while sending an email from cpanel?
我正在嘗試使用mail()函數從我的網站向我的Gmail帳戶發送電子郵件。 這工作正常,但問題是,當我在gmail帳戶收件箱(而不是垃圾郵件)中收到郵件時,出現一個“?” 標記,而不是常規的空白個人資料圖片。 當我將鼠標懸停在“?”上時 標記,彈出消息,提示:“ Gmail無法驗證mywebsite.com是否實際發送了此消息(而非垃圾郵件發送者)”。 我添加了兩張有關此問題的圖片。 我聯系了我的托管服務提供商,他們告訴我這是與腳本相關的問題。 他們通過在Gmail收件箱中單擊“顯示原始文件”來分析我得到的文件。 他們說,發生此問題是因為gmail獲得的“發件人”電子郵件地址是“ cpanel-username@server-hostname.com”,而不是“ myemail@website.com”。 我必須將“ cpanel-username@server-hostname.com”替換為“ myemail@website.com”。 我嘗試了很多,但是無法更改“ from”標題。 我的代碼是這樣的
$Email = "myemail@gmail.com";
$message = "Hello!!";
$headers = "From: Mywebsite <noreply@mywebsite.com>";
$sentmail = mail("$Email",'Something Important',"$message",$headers);
請注意,“ noreply@mywebsite.com”是我在cpanel中創建的真實電子郵件地址。 我也嘗試使用phpmailer解決此問題,但未成功。 我的phpmailer代碼是這樣的
require 'mailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isMail(); // I also tried $mail->isSMTP(), but it does not work. Just keeps loading the page but never completes.
$mail->Host = 'localhost';
$mail->SMTPAuth = true;
$mail->Username = 'noreply@mywebsite.com';
$mail->Password = '****************';
$mail->SMTPSecure = 'tls';
$mail->Port = 365;
$mail->setFrom('noreply@mywebsite.com', 'Mywebsite');
$mail->addAddress('myemail@gmail.com');
$mail->isHTML(true);
$mail->Subject = 'Something Important';
$mail->Body = 'Hello!!';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
但這也不能解決我的問題。 當以gmail接收郵件時,發件人標頭仍為“ cpanel-username@server-hostname.com”。 請有人幫我解決這個問題。
您可以將-f user@domain.tld添加到php.ini中的mail.force_extra_parameters行中。 請參閱此處提供的解決方案。 它幫助了我。 https://forums.cpanel.net/threads/email-sent-as-username-hostname.601655/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.