【发布时间】:2014-06-03 10:41:42
【问题描述】:
- 我一直在尝试使用 xampp 使用 php 发送电子邮件(我使用的是 windows 8.1)
- 我就是搞不定
- 试过 smtp_port= 465/ 587/ 25
- 我已使用 IMAP 启用 gmail
- 从 debug.log 中,我想我已连接到 google
有没有其他方法可以测试我的代码。我想使用 php 发送电子邮件,并在电子邮件中包含 url。
sendemail.ini
[sendmail]
smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=xxxxxxx@gmail.com
auth_password=xxxxxxxx
php.ini
[mail function]
; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury
SMTP=smtp.gmail.com
smtp_port=587
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = xxxxxxx@gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
mail.add_x_header=Off
我使用的php
<?php
$subject = "Simple mail";
$message = "Here is a test mail";
$to = "xxxxxxx@gmail.com";
$from = "xxxxxxx@gmail.com";
$header = "From: ".$from;
if(mail($to, $subject, $message, $header)){
print "success<br>";
}else{
print "fail<br>";}
?>
我在 debug.log 中找到的东西
14/04/19 04:42:11 ** --- MESSAGE BEGIN ---
14/04/19 04:42:11 ** To: xxxxxxxx@gmail.com
14/04/19 04:42:11 ** Subject: Simple mail
14/04/19 04:42:11 ** From: xxxxxxxx@gmail.com
14/04/19 04:42:11 **
14/04/19 04:42:11 ** Here is a test mail
14/04/19 04:42:11 ** --- MESSAGE END ---
14/04/19 04:42:12 ** Connecting to smtp.gmail.com:587
14/04/19 04:42:12 ** Connected.
14/04/19 04:42:12 << 220 mx.google.com ESMTP ac5sm61735964pbc.37 - gsmtp<EOL>
14/04/19 04:42:12 >> EHLO C-PC<EOL>
14/04/19 04:42:12 << 250-mx.google.com at your service, [1.64.44.192]<EOL>250-SIZE 35882577<EOL>250-8BITMIME<EOL>250-STARTTLS<EOL>250-ENHANCEDSTATUSCODES<EOL>250 CHUNKING<EOL>
14/04/19 04:42:12 ** Authenticating as xxxxxxxx@gmail.com
14/04/19 04:42:12 >> STARTTLS<EOL>
14/04/19 04:42:13 << 220 2.0.0 Ready to start TLS<EOL>
14/04/19 04:42:13 >> QUIT<EOL>
14/04/19 04:42:13 << <--some random code here, cannot be copied-->
14/04/19 04:42:13 << <--some random code here again, cannot be copied-->
14/04/19 04:42:13 ** Disconnected.
14/04/19 04:42:13 ** Disconnecting from smtp.gmail.com:587
14/04/19 04:42:13 ** Disconnected.
14/04/19 04:42:13 ** Disconnected.
14/04/19 04:42:13 ** Connection Closed Gracefully.
是 Windows 8.1 还是我错过了一些???我花了将近一天的时间试图解决这个问题。 继续在 php 中失败!
【问题讨论】:
-
您的 ISP 可能会阻止外发电子邮件。我的 ISP 阻止从其 IP 地址发出的外发电子邮件以避免垃圾邮件。也许您的 ISP 也在这样做。 authsmtp.com/faqs/faq-4.html
-
谢谢您的信息。有没有其他方法可以测试我的代码。我想使用 php 发送电子邮件,并在电子邮件中包含 url。
-
您使用的是动态 IP 地址吗?如果您使用的是静态 IP 地址,您是否设置了服务器主机名和地址?
-
我使用的是动态IP地址,我需要这样做吗??