Php 无法从本地主机发送SMTP邮件()
我正在尝试从本地主机发送邮件,但效果不佳。下面是我的代码。请看一下下面的代码,并告诉我们实际的问题是什么。谢谢 我使用的邮件功能->Php 无法从本地主机发送SMTP邮件(),php,Php,我正在尝试从本地主机发送邮件,但效果不佳。下面是我的代码。请看一下下面的代码,并告诉我们实际的问题是什么。谢谢 我使用的邮件功能-> [mail function] ; For Win32 only. ; http://php.net/smtp SMTP = SMTP ; http://php.net/smtp-port smtp_port = 25 ; For Win32 only. ; http://php.net/sendmail-from ;sendmail_from = NULL
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = SMTP
; http://php.net/smtp-port
smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = NULL
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
;sendmail_path = NULL
; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail(), even in safe mode.
;mail.force_extra_parameters = NULL
; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename
mail.add_x_header = Off
; Log all mail() calls including the full path of the script, line #, to address and headers
mail.log = "D:\xampp\apache\logs\php_mail.log"
使用的php代码->
<?php
$to = "somebody@example.com, somebodyelse@example.com";
$subject = "HTML email";
$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags!</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
</table>
</body>
</html>
";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
// More headers
$headers .= 'From: <webmaster@example.com>' . "\r\n";
$headers .= 'Cc: myboss@example.com' . "\r\n";
mail($to,$subject,$message,$headers);
?>
提前感谢。您的SMTP端口25上没有运行邮件服务器。您可以使用IIS附带的SMTP服务器,也可以使用或
服务器管理器>功能(非角色)>右键单击,添加>SMTP服务器-然后配置IIS 7 SMTP以指向本地服务器。SMTP端口25上没有运行邮件服务器。您可以使用IIS附带的SMTP服务器,也可以使用或
服务器管理器>功能(非角色)>右键单击,添加>SMTP服务器-然后配置IIS 7 SMTP以指向本地服务器。这里有一个简单的python脚本,允许您在wamp中的本地主机上运行邮件服务器,您不必在php.ini中更改任何内容
import smtpd
import smtplib
import asyncore
class SMTPServer(smtpd.SMTPServer):
def __init__(*args, **kwargs):
print "Running smtp server on port 25"
smtpd.SMTPServer.__init__(*args, **kwargs)
def process_message(*args, **kwargs):
to = args[3][0]
msg = args[4]
gmail_user = 'yourgmailhere'
gmail_pwd = 'yourgmailpassword'
smtpserver = smtplib.SMTP("smtp.gmail.com",587)
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.ehlo
smtpserver.login(gmail_user, gmail_pwd)
smtpserver.sendmail(gmail_user, to, msg)
print 'sent to '+to
pass
if __name__ == "__main__":
smtp_server = SMTPServer(('localhost', 25), None)
try:
asyncore.loop()
except KeyboardInterrupt:
smtp_server.close()
#end of code
注意:我使用args[3][0]和args[4]作为地址和消息,因为我的php mail()发送的args对应于一个args[3][0]数组作为最近的电子邮件这里有一个简单的python脚本,允许您在wamp中的本地主机上运行邮件服务器,您不必在php.ini中更改任何内容
import smtpd
import smtplib
import asyncore
class SMTPServer(smtpd.SMTPServer):
def __init__(*args, **kwargs):
print "Running smtp server on port 25"
smtpd.SMTPServer.__init__(*args, **kwargs)
def process_message(*args, **kwargs):
to = args[3][0]
msg = args[4]
gmail_user = 'yourgmailhere'
gmail_pwd = 'yourgmailpassword'
smtpserver = smtplib.SMTP("smtp.gmail.com",587)
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.ehlo
smtpserver.login(gmail_user, gmail_pwd)
smtpserver.sendmail(gmail_user, to, msg)
print 'sent to '+to
pass
if __name__ == "__main__":
smtp_server = SMTPServer(('localhost', 25), None)
try:
asyncore.loop()
except KeyboardInterrupt:
smtp_server.close()
#end of code
注意:我使用args[3][0]和args[4]作为地址和消息,因为我的php mail()发送的args对应于args[3][0]数组作为最近的电子邮件您使用的是什么本地主机程序?例如WAMP、XAMPP或本地VM?您需要指定SMTP服务器的域或IP地址。在php.ini文件中,“SMTP”是对您实际安装的本地SMTP服务器的引用吗?如果没有,则需要安装和设置SMTP服务器。您可以从web下载免费的SMTP服务器。XAMPP附带Pegasus Mercury SMTP服务器,您可以启动该服务器。如果不下载SMTP服务器,则无法直接使用SMTP服务器。您使用的是什么本地主机程序?例如WAMP、XAMPP或本地VM?您需要指定SMTP服务器的域或IP地址。在php.ini文件中,“SMTP”是对您实际安装的本地SMTP服务器的引用吗?如果没有,则需要安装和设置SMTP服务器。您可以从web下载免费的SMTP服务器。XAMPP附带Pegasus Mercury SMTP服务器,您可以启动该服务器。如果不下载SMTP服务器,则无法直接使用SMTP服务器。我必须先安装邮件程序。是的,您需要先安装邮件程序,然后才能发送邮件。正如Imran Azad在评论中建议的那样,XAMPP附带了一个可以使用的SMTP服务器,我必须先安装邮件程序。是的,在发送邮件之前,您需要先安装邮件程序。正如Imran Azad在评论中所建议的那样,XAMPP附带了一个可以使用的SMTP服务器,