[英]sendmail.exe opens on sending mail
我實際上是使用sendmail的新手,但我已經閱讀了很多關於這個,並且只重定向我使用PHPmailer,swiftmailer等...但是如果不了解基礎知識就很難理解。 所以我決定嘗試簡單,這就是我所擁有的。
我配置了我的php.ini:
[mail function]
smtp_port = 465
sendmail_path="C:\wamp\sendmail\sendmail.exe -t"
mail.add_x_header = On
我的sendmail.ini:
[sendmail]
smtp_server=smtp.gmail.com
smtp_port=587
smtp_ssl=
error_logfile=error.log
debug_logfile=debug.log
auth_username=mygmail@gmail.com
auth_password=mypassword
hostname=localhost
我有這個PHP代碼:
$to = 'mygmail@gmail.com';
$message = $_POST['message'];
$email = $_POST['email'];
$contact_num = $_POST['contact_number'];
$headers = 'From:'.'$email' . "\r\n" .'$contact' . "\r\n" .
'Reply-To: mygmail@gmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $message, $headers);
但是,當我單擊提交按鈕時,sendmail.exe出現,沒有任何反應。 當我檢查error.log時,它說:
14/07/01 23:23:48 : Connection Closed Gracefully.
這部分是帖子的復制和粘貼: Sendmail Wamp Php
問題是sendmail必須以管理員身份運行。 這是幫助任何人解決我的情況的解決方案。
以管理員身份執行
如果您使用Gmail,則需要創建新密碼“您的應用程序專用密碼”
如果那仍然不起作用(我的回答)
通過以下任一方式確保服務器(或IDE)作為管理員運行:
1)右鍵單擊程序(例如server,ide,命令提示符)並單擊“Run as Administer”
2)或右鍵單擊程序>屬性>兼容性>勾選執行為admin
例如,如果您在構建的服務器中使用PHP,請以管理員身份運行命令提示符並正常啟動服務器
C:\wamp\bin\php\php5.5.12\php.exe -S localhost:80 -t C:\Users\path\to\rootFolder
當然,更改文件路徑以滿足您的需求。
編輯:這可能是您進入https://bugs.php.net/bug.php?id=44994的錯誤
解決方案是設置sendmail.ini和php.ini
你需要與你的isp溝通,找出什么是開放的smtp服務器,他們大多數都有一個,它就像smtp.yourisp.com大多數時間。
您也可以使用自己的電子郵件服務器或現有的電子郵件地址設置smtp,這將需要其他設置,如特定的smtp服務器,端口號,強制sendmail成為實際的郵件,用戶名,密碼和大多數時間ssl
php.ini中
; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury SMTP = smtp.yourisp.mu smtp_port = 25
; For Win32 only. ; http://php.net/sendmail-from sendmail_from = postmaster@yourisp.com
; XAMPP IMPORTANT NOTE (1): If XAMPP is installed in a base directory with spaces (e.g. c:\program filesC:\xampp) fakemail and mailtodisk do not work correctly. ; XAMPP IMPORTANT NOTE (2): In this case please copy the sendmail or mailtodisk folder in your root folder (e.g. C:\sendmail) and use this for sendmail_path. ; XAMPP: Comment out this if you want to work with fakemail for forwarding to your mailbox (sendmail.exe in the sendmail folder) sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
; XAMPP: Comment out this if you want to work with mailToDisk, It writes all mails in the C:\xampp\mailoutput folder ;sendmail_path="C:\xampp\mailtodisk\mailtodisk.exe"
確保php和sendmail以管理員身份運行似乎是一個好主意,但這並沒有解決我的問題。
sendmail.ini中的解決方案
smtp_server = smtp.yourisp.com
; smtp port (normally 25)
smtp_port=25
; SMTPS (SSL) support
; auto = use SSL for port 465, otherwise try to use TLS
; ssl = alway use SSL
; tls = always use TLS
; none = never try to use SSL
smtp_ssl=none
不要使用 smtp_ssl = auto這是導致我的錯誤只是根據你的服務器規范將其設置為ssl tls或none
確保XAMPP以管理員身份運行。 通過右鍵單擊它並單擊“以管理員身份運行”來執行此操作。 這為我解決了這個問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.