php - 用 PHP 从本地服务器发送电子邮件

标签 php

我有我的文件 mail.php :

<html>
<body>

<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
  {
  //send email
  $email = $_REQUEST['email'] ;
  $subject = $_REQUEST['subject'] ;
  $message = $_REQUEST['message'] ;
  mail("<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a8dbd1cdccdbc9c5c1daddccccc1c69a91e8cfc5c9c1c486cbc7c5" rel="noreferrer noopener nofollow">[email protected]</a>", $subject,
  $message, "From:" . $email);
  echo "Thank you for using our mail form";
  }
else
//if "email" is not filled out, display the form
  {
  echo "<form method='post' action='mail.php'>
  Email: <input name='email' type='text' /><br />
  Subject: <input name='subject' type='text' /><br />
  Message:<br />
  <textarea name='message' rows='15' cols='40'>
  </textarea><br />
  <input type='submit' />
  </form>";
  }
?>

</body>
</html>

但是当我运行它时。我收到此错误:

Warning: mail() [function.mail]: Failed to connect to mailserver at "127.0.0.1" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\Program Files\EasyPHP-5.3.8.1\www\safepay247\mail.php on line 13
Thank you for using our mail form

我想做的是发送一封电子邮件到我的电子邮件 ID:[email protected]使用 php 以输入类型写入该人的电子邮件。

我看过很多视频,但没有一个能帮助我解决 php.ini 问题。

最佳答案

您需要在 php.ini 中设置 SMTP 服务器。

列出了您需要更改的指令 here 。这些设置应由您的托管提供商提供。

但在我们言过其实之前,先简单警告一下:

  • 您通过在“发件人” header 中设置电子邮件来伪装成其他人来发送电子邮件。

  • 大多数 SMTP 服务器都需要某种形式的身份验证,例如要使用 gmail SMTP 服务器发送内容,我需要使用我的用户名和密码进行身份验证。

  • 如果表单字段中的电子邮件与身份验证用户名不匹配,服务器可能会拒绝该电子邮件,或者更改它以反射(reflect)身份验证用户名。最后,它可能无法与垃圾邮件过滤器很好地配合。

我的建议是您从自己的电子邮件帐户之一发送电子邮件,例如 ( [email protected] )。然后在消息正文中输入客户的电子邮件地址。您还可以将reply-to header 设置为客户的电子邮件地址,以便在电子邮件客户端中点击“回复”时会自动将其电子邮件地址放入“收件人”字段中。

关于php - 用 PHP 从本地服务器发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9660057/

相关文章:

php - 如何在 PHP 中替换变音字符或非重音符号?

PHP 自动加载忽略大小写

php - 从 laravel 中传递的数组对象更新 DB::table

php - PHP应用程序如何与ERP系统连接?

PHP - 从字符串中删除解码的 HTML 实体

php - MySQL创建触发器将内容插入同一数据库中的另一个表中

PHP 变量在 SQL 查询中不起作用?

php - 并行运行 Node.js 和 apache 的技术方面

javascript - Ajax 表单无法使用 event.preventDefault() 阻止页面重新加载;

php - 如何在给定的时间间隔内显示循环元素?