PHP脚本不发送/接收电子邮件

时间:2013-07-18 19:48:36

标签: php html

我有一个网站,其表格可能会向我的公司发送电子邮件,另一个网站会向填写表格的用户发送电子邮件。我已经将包含所有附加文件的站点加载到服务器,但是当我填写表单来测试它时会弹出一个错误,说“找不到”。我正在使用PHP的GET方法来处理它。我是PHP的新手,也是Web设计的新手。谢谢。

<?php
//Function that sends the email to the person who submitted the form
function send_email(){
//This sends an email to the person who submitted the form
// email fields: to, from, subject. Put your values here!
$sendermail = 'company@email.com';
$from = "Company<".$sendermail.">";
$to = $_GET['email'];
$subject = 'Product Information';
$message = "A member of our sales team will be getting back to you shortly.  Thank you for your interest in our great line of products."."\n\n"."Best Regards,"."\n\n"."The Team";
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/plain; charset=iso-8859-1' . "\n";
$headers .= 'From: '. $from . "\r\n" .
'Reply-To: '. $sendermail. "\r\n" .
'X-Mailer: PHP/' . phpversion();

$ok = @mail($to, $subject, $message, $headers);

//This sends the contents of the form submission to the website owner
$sendermail2 = $_GET['email'];
$from2 = $_GET['first-name'].' '.$_GET['last-name'].' <'.$sendermail2.'>';
$to2 = 'company@email.com';
$subject2 = 'A customer submission from the product page';
$message2 = "Name: ". $_GET['first-name'] ." ". $_GET['last-name'] ."\n\n". "Company: ". $_GET['company'] ."\n\n". "Email: ". $_GET['first-name'] ."\n\n". "Interest: ".$_GET['Interest'];
$headers2  = 'MIME-Version: 1.0' . "\r\n";
$headers2 .= 'Content-type: text/plain; charset=iso-8859-1' . "\n";
$headers2 .= 'From: '. $from2 . "\r\n" .
'Reply-To: '. $sendermail2. "\r\n" .
'X-Mailer: PHP/' . phpversion();

$ok2 = @mail($to2, $subject2, $message2, $headers2);
}
return send_email();
?>

...此代码位于HTML页面的正文中。

<FORM ACTION="http://www.server.com/html/form_process.php" METHOD=GET>

2 个答案:

答案 0 :(得分:0)

红帽服务器的解决方案:

sudo yum install postfix

接着:

sudo echo "sendmail_from = me@example.com" >> /your/directory/php.ini

最后:

sudo echo "sendmail_path = /usr/sbin/sendmail -t -i -f me@example.com" >> /your/directory/php.ini

将/your/directory/php.ini替换为您真正的php.ini目录,将me@example.com替换为您想要的电子邮件地址,然后重新启动apache,php和postfix,或者直接重启服务器。

答案 1 :(得分:0)

未找到错误通常意味着您将表单发送到错误的URL。检查您要发送到的URL以及php文件的路径以查看它们是否正确