php 帮助

发布于 2024-08-16 06:39:29 字数 1893 浏览 2 评论 0原文

我从表单发送邮件时遇到错误

无法连接到“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

南汐寒笙箫 2024-08-23 06:39:29

您正在使用 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 .

只是一片海 2024-08-23 06:39:29

消息 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.

兔小萌 2024-08-23 06:39:29

如果您希望使用身份验证,则需要安装此 PEAR 模块,因为未提供身份验证在PHP的邮件功能中。

使用 SMTP 身份验证从 PHP 发送邮件 - 示例

<?php
require_once "Mail.php";

$from = "Sandra Sender <[email protected]>";
$to = "Ramona Recipient <[email protected]>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";

$host = "mail.example.com";
$username = "smtp_username";
$password = "smtp_password";

$headers = array ('From' => $from,
  'To' => $to,
  'Subject' => $subject);
$smtp = Mail::factory('smtp',
  array ('host' => $host,
    'auth' => true,
    'username' => $username,
    'password' => $password));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
  echo("<p>" . $mail->getMessage() . "</p>");
 } else {
  echo("<p>Message successfully sent!</p>");
 }
?>

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
require_once "Mail.php";

$from = "Sandra Sender <[email protected]>";
$to = "Ramona Recipient <[email protected]>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";

$host = "mail.example.com";
$username = "smtp_username";
$password = "smtp_password";

$headers = array ('From' => $from,
  'To' => $to,
  'Subject' => $subject);
$smtp = Mail::factory('smtp',
  array ('host' => $host,
    'auth' => true,
    'username' => $username,
    'password' => $password));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
  echo("<p>" . $mail->getMessage() . "</p>");
 } else {
  echo("<p>Message successfully sent!</p>");
 }
?>
只是在用心讲痛 2024-08-23 06:39:29

基本上,如果您在托管服务器上,那么使用 php 发送电子邮件就像喝冷水一样简单。

if(mail('[email protected]','subject','content here i include sometime var_export($var,1)'))
 echo 'email send succefull';
else
  echo 'emaiol coudnt be send';

如果您从本地计算机发送此消息,这通常会失败,因为大多数服务器拒绝这样的请求。
然后,您必须使用外部库从 gmail 等服务发送电子邮件。

basicaly if you are on a hosted server then sending an email with php is easy as drinking cold water.

if(mail('[email protected]','subject','content here i include sometime var_export($var,1)'))
 echo 'email send succefull';
else
  echo 'emaiol coudnt be send';

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.

昨迟人 2024-08-23 06:39:29

正如 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文