dtng25909 2019-02-02 14:47
浏览 85
已采纳

Php电子邮件表单不从Web电子邮件表单发送电子邮件

I am trying to troubleshoot this form. It is not sending reservation requests from the form on the website. Despite showing a message that the form was sent.

I tried editing email and the headers.

<?
//print_r($_POST);

$to = “email@emaildomain.com, {$posting['email']}";
function msg($text){
echo "
    <script type='text/javascript'>
    alert('".$text."');
    top.location.href = 'http://www.aribbq.com';
    </script>
";
exit;
}

function error($text){
echo "
    <script type='text/javascript'>
    alert('".$text."');
    history.go(-1);
    </script>
";
exit;
}

if (!$_POST[date]) {error('Please, insert Date.');}
if (!$_POST[time]) {error('Please, insert Time.');}
if (!$_POST[party]) {error('Please, insert Party.');}
if (!$_POST[reservation_name]) {error('Please, insert Name.');}
if (!$_POST[reservation_email]) {error('Please, insert Email.');}
if (!$_POST[reservation_phone]) {error('Please, insert Phone.');}  
if(isset($_POST['submit'])){
 // then send the form to your email

//$from = ('Reservation from AriBBQ.com'); // sender
$mailheaders = "From: contact@aribbq.com" . "
"; // . "CC: 
design@youremail.com"
$mailheaders .= 'Reply-To: ' . $posting['Email'] . "
";
$subject = "AriBBQ.com Online Reservation";
$body = "
 Contact Name: ".$_POST[reservation_name]." 

"; 
//
$body .= " Email: ".$_POST[reservation_email]." 

"; //
$body .= " =================================================== 

"; //
$body .= "  Book a table 


            Date: ".$_POST[date]." 


            Time: ".$_POST[time]." 


            Party: ".$_POST[party]." 


            Contact Details 


            Name: ".$_POST[reservation_name]." 


            Email: ".$_POST[reservation_email]." 


            Phone: ".$_POST[reservation_phone]." 


            Message: ".$_POST[reservation_message]." 

"; //
$body .= " =================================================== 

"; //


$result = mail($to , $from , $subject , $body , $mailheaders); 
if($result) {msg('Thank you, your reservation has been sent. We 
will send you a confirmation text or call in person.');} // 
else{error('Sending mail is failed. Please try again');} //

} else {
error('No submitted. Please try again');
}

?>

You see the form online at http://aribbq.com/. Click on reservations. Once the email is received, we want to be able to reply to the sender's email address.

  • 写回答

2条回答 默认 最新

  • douye6812 2019-02-02 15:45
    关注

    Alright, essentially, you need to turn on error reporting because your script threw about 20 errors at me which you would see with error reporting on. As my comment above said, add error_reporting(E_ALL); to the top of your script while you debug.

    The issues I came across are as follows:

    Parse error: syntax error, unexpected '@' in /mail.php on line 4 caused by an incorrect double quote character, not " but . Subtle, but problematic.

    Next up, Multiple or malformed newlines found in additional_header in /mail.php because as of PHP 5.5.2, a bug was fixed to prevent mail header injection, so all of your within the $mailheaders should be removed, I recommend appending PHP_EOL to the end of each line instead.

    You have your $from variable included in the mail() call, this presents 2 issues. One, the mail() function does not have a from parameter, you include it within the headers. Two - your variable is actually commented out.

    As I mentioned in the comment above, again, your email address variable to send to is typed as $posting['email']', and $posting['Email'] within $mailheaders. The problem here is $posting doesn't exist. Secondly, your form, which you should include the HTML for in future questions for self-contained examples for people to more easily help you (see https://stackoverflow.com/help/how-to-ask), doesn't post email at all, it posts reservation_email.

    Finally, the majority of your $_POST references do not include quotes so PHP doesn't know what to do with the words in between the square brackets. $_POST[date] should be $_POST['date'], for example.

    I've made all the above changes and managed to successfully email myself with the script and email form provided, the only thing that I didn't look at was your msg() which didn't show me a success message. I did, however, put an echo statement before this function call which printed out fine.

    I hope this helps you get your script up and running, good luck and remember, error_reporting(); is your friend!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测