我尝试从本地主机发送邮件,但它不能正常工作。下面给出我的代码。请看下面的代码,并请告诉实际问题是什么。由于无法从本地主机发送SMTP邮件()
邮件功能我用 - >
[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 = "[email protected], [email protected]";
$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: <[email protected]>' . "\r\n";
$headers .= 'Cc: mybo[email protected]' . "\r\n";
mail($to,$subject,$message,$headers);
?>
得到错误当执行PHP代码上文>
Warning: mail() [function.mail]: Failed to connect to mailserver at "SMTP" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in D:\xampp\htdocs\mail.php on line 43
在此先感谢。
您使用的是什么localhost程序?例如WAMP,XAMPP或本地VM? – Jelmer
我使用了XAMPP服务器。 – Vaibhav
您需要指定SMTP服务器的域或IP地址。在您的php.ini文件中是“SMTP”对实际设置的本地SMTP服务器的引用?如果没有,您需要安装并设置SMTP服务器。您可以从网上下载免费的SMTP服务器。 –