簡體   English   中英

通過PHP函數發送郵件

[英]Sending mail via PHP function

我正在嘗試使用sendmail(在/ usr / sbin / sendmail中 )從服務器PLESK 通過PHP mail()函數發送電子郵件。

我已經閱讀了約翰·康德(John Conde)的清單,此處的PHP郵件功能無法完成電子郵件的發送,而我的問題很可能與提供商有關,因為我的腳本向gmail帳戶發送了電子郵件,但沒有其他人發送。 發送到gmail帳戶的電子郵件將進入SPAM文件夾。 例如,我正在嘗試發送到name@company.it

在您問我之前,我已經檢查了我的發件人IP信譽,驗證了反向DNS結果並在http://mail-tester.com/ [垃圾郵件檢查器]上獲得了9分(滿分10分)。

在域的php.ini中,我輸入以下字段:SMTP,smtp_port,sendmail_from,sendmail_path,auth_password和auth_username。 (因為我在域上具有SSL證書,所以我在提供商smtp服務器上使用465端口)。

這是代碼片段:

<?php
    error_reporting(-1);
    ini_set('display_errors', 'On');
    ini_set('display_startup_errors', 1);
    set_error_handler("var_dump");

    //
    $replyTo = "website@globalpower.it";
    $mailTo  = "fcaliari@e-globalservice.it";

    //Test sender delle Email
    $headers = 'From: '.$replyTo."\r\n".
               'Reply-To: '.$replyTo."\r\n" .'X-Mailer: PHP/' . phpversion();

    if (mail($mailTo,"Title","Body of the message",$headers)){
       echo "Mail ok";
    } else {
       echo "Error Mail";
    }
?>

這是郵件目錄下服務器的日志

Aug 23 10:38:20 webserver check-quota[1905]: Starting the check-quota filter...
Aug 23 10:38:20 webserver journal: plesk sendmail[1904]: handlers_stderr: SKIP
Aug 23 10:38:20 webserver journal: plesk sendmail[1904]: SKIP during call 'check-quota' handler
Aug 23 10:38:20 webserver postfix/pickup[1560]: DAC521A8B: uid=10003 from=<rootgp@globalpower.it>
Aug 23 10:38:20 webserver postfix/cleanup[1910]: DAC521A8B: message-id=<20180823143820.DAC521A8B@webserver.e-globalservice.it>
Aug 23 10:38:20 webserver postfix/qmgr[1561]: DAC521A8B: from=<rootgp@globalpower.it>, size=450, nrcpt=1 (queue active)
Aug 23 10:38:20 webserver postfix-local[1915]: postfix-local: from=rootgp@globalpower.it, to=fcaliari@e-globalservice.it, dirname=/var/qmail/mailnames
Aug 23 10:38:20 webserver postfix-local[1915]: cannot chdir to mailname dir fcaliari: No such file or directory
Aug 23 10:38:20 webserver postfix-local[1915]: Unknown user: fcaliari@e-globalservice.it
Aug 23 10:38:20 webserver postfix/pipe[1914]: DAC521A8B: to=<fcaliari@e-globalservice.it>, relay=plesk_virtual, delay=0.05, delays=0.03/0.01/0/0.01, dsn=2.0.0, status=sent (delivered via plesk_virtual service)
Aug 23 10:38:20 webserver postfix/qmgr[1561]: DAC521A8B: removed

在日志中顯示此電子郵件rootgp@gloablpower.it ,我從未在php.ini文件或腳本中使用過

任何幫助表示贊賞!

php腳本中發送郵件時,我強烈建議使用SMTP中繼通過專用電子郵件服務器發送電子郵件,而不是直接通過Web服務器發送。 原因是:如果您托管在共享服務器上,則也有可能同時托管在該服務器上的其他人發送垃圾郵件(這將導致您的電子郵件被標記為垃圾郵件)。

我在使用PHPMailer方面有豐富的經驗,可以進行很多設置來進行調整,以使設置與您的環境/設置一起使用。

有關參考,請參閱: https : //github.com/PHPMailer/PHPMailer

暫無
暫無

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

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