如何发送电子邮件在PHP可靠? [英] How to send an email in PHP reliably?

查看:120
本文介绍了如何发送电子邮件在PHP可靠?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习如何发送email.i已经安装了appserver和文件
php.ini-dist和php.ini - 推荐我做了以下更改

  SMTP = localhost 

sendmail_from = me@localhost.com

我用mail.ptcl.net替换了本地主机,这是我的dsl提供程序
,并用我的电子邮件地址替换了me@localhost.com h_k9@live.com



当我提交表单时,我收到以下消息


warning:mail()[function。邮件]:
sendmail_from未在php.ini中设置或
自定义From:头文件
中缺少C:\AppServ\www\Hamza\send_simpleform.php
在第14行以下电子邮件已发送



Hamza:hamza



h_k9@live.com



消息:adasdas


是我正在使用的脚本

 < html> 
< head>
< title>简单反馈表单< / title>
< / head>
< body>
< form method =postaction =send_simpleform.php/>
< p>< strong>您的姓名< / strong>< br />
< input type =textname =sender_namesize =30/>< / p>
< p>< strong>发件人电子邮件地址< / strong>< br />
< input type =textname =sender_emailsize =30/>< / p>
< p>< strong>在此输入您的讯息< / strong>< br />
< textarea name =messagecols =30rows =5wrap =virtual>< / textarea>< / p>
< p>< input type =submitvalue =发送此表单name =submit/>< / p>
< / form>
< / body>
< / html>如果(($ _ POST [sender_name] ==)||($ _ POST [sender_email] =)||($ _ POST),


<?php
[message ==]))
{header(location = simple_form.html);
退出;
}
$ msg =电子邮件从WWW SITE\\\
;
$ msg =发件人姓名:$ _POST [sender_name] \\\
;
$ msg =发件人的E-Mal I.D:$ _POST [sender_email] \\\
;
$ msg =消息:$ _POST [message] \\\
;
$ to =h_k9@live.com;
$ subject =网站反馈;
$ mailholders =来自我的网站< geriadress@yourdomain.com> \\\
;
$ mailheader =回覆:$ _POST [sender_email] \\\
;
mail($ to,$ subject,$ msg,$ mailheaders);
?>
< html>
< head>
< title>发送简单的反馈表格< / title>
< / head>
< body>
< h1>以下电子邮件已发送:< / h1>
< p>< strong> Hamza:< / strong>< br\>
<?php echo$ _POST [sender_name];?>
< p>< strong> h_k9@live.com< / strong>< br \>
<?php echo$ _POST [sender_email];?>
< p>< strong>消息:< / strong>< br>
< echo$ _POST [message];?>
< / body>
< / html>


解决方案

我相信你至少有两个问题: p>


  1. 我猜想 php.ini推荐 php .ini-dist 分别是一个示例和一个模板配置文件;对它们的修改可能不会影响PHP实例目前使用的真实 php.ini 。使用 phpinfo() 以确保您的配置正确。

  2. 垃圾邮件过滤器。 Jeff Atwood有一个很好的博客关于实施服务器检查您的电子邮件是否是垃圾邮件时执行的检查。不要忘记:




只是因为你发送这意味着它会到达。



i am learning how to send an email.i have installed appserver and in files php.ini-dist and php.ini-recommended i did the following changes

SMTP=localhost

sendmail_from=me@localhost.com

i replaced localhost with mail.ptcl.net which is my dsl provider and replaced me@localhost.com with my email address h_k9@live.com

i get the following message when i submit the form

"warning: mail() [function.mail]: "sendmail_from" not set in php.ini or custom "From:" header missing in C:\AppServ\www\Hamza\send_simpleform.php on line 14 The following e-mail has been sent:

Hamza: hamza

h_k9@live.com

Message: adasdas"

following is the script i am using

<html>
<head>
<title>Simple Feedback Form</title>
</head>
<body>
<form method="post" action="send_simpleform.php"/>
<p><strong>Your name</strong><br/>
<input type="text" name="sender_name" size="30" /></p>
<p><strong>Senders Email address</strong><br/>
<input type="text" name="sender_email" size="30" /></p>
<p><strong>Enter your Message here</strong><br/>
<textarea name="message" cols="30" rows="5" wrap="virtual"></textarea></p>
<p><input type="submit" value="send this form" name="submit"/></p>
</form>
</body>
</html>


<?php
if(($_POST[sender_name]=="")||($_POST[sender_email]="")||($_POST[message==""]                                                                                                          ))
{   header("location=simple_form.html");
    exit;
}
$msg="E-MAIL SENT FROM WWW SITE\n";
$msg="Sender's Name:  $_POST[sender_name]\n";
$msg="Sender's E-Mal I.D:    $_POST[sender_email]\n";
$msg="Message:                 $_POST[message]\n";
$to="h_k9@live.com";
$subject="Web site feedback";
$mailholders="from my website<geriadress@yourdomain.com>\n";
$mailheader="Reply-to: $_POST[sender_email]\n";
mail($to, $subject,$msg,$mailheaders);
?>
<html>
<head>
<title>Simple Feedback Form Sent</title>
</head>
<body>
<h1>The following e-mail has been sent:</h1>
<p><strong>Hamza:</strong><br\>
<?php echo "$_POST[sender_name]";?>
<p><strong>h_k9@live.com</strong><br\>
<?php echo "$_POST[sender_email]";?>
<p><strong>Message:</strong><br>
<? echo "$_POST[message]";?>
</body>
</html>

解决方案

I believe you have at least two problems:

  1. I am guessing that php.ini-recommended and php.ini-dist are respectively an example and a template configuration files; modifications to them may not impact the "real" php.ini, currently used by your instance of PHP. Use phpinfo() to make sure that your configuration is correct.
  2. Spam filters. Jeff Atwood has a pretty good blog post about implementing the checks that servers do when checking if your email message is spammy. Don't forget:

Just because you send an email doesn't mean it will arrive.

这篇关于如何发送电子邮件在PHP可靠?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆