php 帮助
我从表单发送邮件时遇到错误
无法连接到“mail.yoursite.com”端口 25 的邮件服务器,请验证 php.ini 中的“SMTP”和“smtp_port”设置或使用 C 中的 ini_set(): \xampp\xampp\htdocs\send.php 第 8 行
警告:mail() [function.mail]: SMTP 服务器响应:550 ACCESS DENIED in C:\xampp\xampp\htdocs\send.php 第 9 行
消息传递失败...
这是代码
mail.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form action="send.php" action="POST">
Enter Name : <input type="text" name="name" />
Enter E-Mail : <input type="text" name="email" />
Enter Subject: <input type="text" name="subject" />
Enter Message: <input type="text" name="mess" />
<input type="submit" name="Submit" />
</form>
<?php
?>
</body>
</html>
send.php
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$body = $_POST['subject'];
$message=$_POST['message'];
//ini_set("sendmail_from","[email protected]");
//ini_set("SMTP","mail.yoursite.com");
mail("[email protected]", $name, $message, "From :$from");
if (mail('[email protected]', $name, $body, $message, "From :$from")) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
?>
I am getting an error while sending a mail from a form
Failed to connect to mailserver at "mail.yoursite.com" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\xampp\xampp\htdocs\send.php on line 8
Warning: mail() [function.mail]: SMTP server response: 550 ACCESS DENIED in C:\xampp\xampp\htdocs\send.php on line 9
Message delivery failed...
here is the code
mail.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form action="send.php" action="POST">
Enter Name : <input type="text" name="name" />
Enter E-Mail : <input type="text" name="email" />
Enter Subject: <input type="text" name="subject" />
Enter Message: <input type="text" name="mess" />
<input type="submit" name="Submit" />
</form>
<?php
?>
</body>
</html>
send.php
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$body = $_POST['subject'];
$message=$_POST['message'];
//ini_set("sendmail_from","[email protected]");
//ini_set("SMTP","mail.yoursite.com");
mail("[email protected]", $name, $message, "From :$from");
if (mail('[email protected]', $name, $body, $message, "From :$from")) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您正在使用 win32 版本的 php 及其 mail() 的 smtp 实现。它是一个很小的 MTA,无法进行任何类型的身份验证。如果您尝试将电子邮件中继到的 smtp 服务器要求您验证 mail() 将失败。
使用(并配置)win32 的 sendmail。或者实现身份验证的邮件程序类/库,例如 SwiftMailer。
顺便说一句:Xampp 捆绑了 Mercury smtp 服务器。在其默认配置中,它接受来自本地 php 脚本的电子邮件。但是你必须配置mecury 将电子邮件转发到另一个 MTA 。
You're using a win32 version of php and its smtp-implementation of mail(). It's a tiny little MTA that can't do authentication of any kind. If the smtp server you're trying to relay the email to requires you to authenticate mail() will fail.
Either use (and configure) sendmail for win32. Or a mailer class/library that implements authentication, e.g. SwiftMailer.
btw: Xampp bundles the mercury smtp server. In its default configuration it accepts emails from local php scripts. But then you have to configure mecury to relay the emails to another MTA .
消息
SMTP 服务器响应:550 ACCESS DENIED
建议我再次检查该服务器的凭据。您的用户名或密码可能不正确。The message
SMTP server response: 550 ACCESS DENIED
suggests to me that you should check your credentials for that server again. Your username, or password may be incorrect.如果您希望使用身份验证,则需要安装此 PEAR 模块,因为未提供身份验证在PHP的邮件功能中。
使用 SMTP 身份验证从 PHP 发送邮件 - 示例
You need to install this PEAR Module if you wish to use authentication as it is not provided in the mail function of PHP.
Sending Mail from PHP Using SMTP Authentication - Example
基本上,如果您在托管服务器上,那么使用 php 发送电子邮件就像喝冷水一样简单。
如果您从本地计算机发送此消息,这通常会失败,因为大多数服务器拒绝这样的请求。
然后,您必须使用外部库从 gmail 等服务发送电子邮件。
basicaly if you are on a hosted server then sending an email with php is easy as drinking cold water.
if you send this from your localmachine this will mostly fail because most server refuse requests like this.
Then you have to use an external library for sending your email from a service like gmail.
正如 VolkerK 指出的那样 - 使用 Swiftmail,它是独立的,不需要 SMTP 服务器。我用了 Mercury + xampp 两天,无法让它工作。
此链接中的第一个示例立即生效:
http://swiftmailer.org/docs/sending.html
As VolkerK pointed - use Swiftmail, its selfcontained, no need for a SMTP server. I used two days with Mercury + xampp, couldnt make it work.
First example in this link works right away:
http://swiftmailer.org/docs/sending.html