首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用PHP脚本在填写表单后发送邮件

用PHP脚本在填写表单后发送邮件
EN

Stack Overflow用户
提问于 2015-04-15 16:09:02
回答 3查看 784关注 0票数 1

在当地足球队(在这里输入链接描述,由One.com主办)的网站上,我为每一场比赛(8场比赛)的8场比赛编制了一个足球博彩程序。当用户填写表格并提交时,他会收到一封带有投注的邮件,网站管理员收到一份Bcc的副本。邮件从域doskobeveren.be: info@doskobeveren.be的主邮箱发送到用户的邮件地址。

自2013-2014季和2014-2015年前28周以来,剧本一直运转良好(= 58周)。但自上周以来,脚本中的密件抄送部分在主邮箱(info@doskobeveren.be)中为每封邮件提供了一个“未发送邮件返回发件人”,而不是网站管理员的邮箱。

:Reporting-MTA: dns;mail-out2.one.com X-后缀-队列-ID: 9ABF0552A2 X-后缀-发件人: rfc822;info@doskobeveren.be到达日期:16,2015年4月15日17:36:16 +0200 (CEST)

最终收件人: rfc822;webmaster@doskobeveren.be原始收件人:rfc822;webmaster@doskobeveren.be操作:失败状态: 5.7.1远程-MTA: dns;mxcluster2.one.com诊断-代码: smtp;550 5.7.1被电子邮件过滤器阻塞

(27ec3383-e385-11e4-9d60-b82a72d88088)

One.com的支持告诉我,原因如下:

  • 信息不对-身份证。
  • 使用的域名不正确。

因为邮件是由网页制作的,我想知道PHP脚本是否导致了58周工作后突然出现的问题?

PHP来自:在这里输入链接描述

代码语言:javascript
复制
enter code here
代码语言:javascript
复制
<h3>Dit bericht zal u per mail ontvangen:</h3>  
    <?php   
        $pronomail ='';
        $pronomail = $_SESSION['username']. ", u heeft de volgende pronostiek ingestuurd voor speeldag " .$speeldag. "\n\n";

        for($i=1; $i<=8; $i++){
            $pronomail .=  "wedstrijd " .$i. ": " .$wedstrijd[$i]. " = ";
            switch ($i) {
                case 1:
                    $pronomail .= "Prono1: " .$k1w1. " - Prono2: " .$k2w1. " - Prono3: " .$k3w1. "\n\n";
                    break;
                case 2:
                    $pronomail .= "Prono1: " .$k1w2. " - Prono2: " .$k2w2. " - Prono3: " .$k3w2. "\n\n";
                    break;
                case 3:
                    $pronomail .= "Prono1: " .$k1w3. " - Prono2: " .$k2w3. " - Prono3: " .$k3w3. "\n\n";
                    break;
                case 4:
                    $pronomail .= "Prono1: " .$k1w4. " - Prono2: " .$k2w4. " - Prono3: " .$k3w4. "\n\n";
                    break;
                case 5:
                    $pronomail .= "Prono1: " .$k1w5. " - Prono2: " .$k2w5. " - Prono3: " .$k3w5. "\n\n";
                    break;
                case 6:
                    $pronomail .= "Prono1: " .$k1w6. " - Prono2: " .$k2w6. " - Prono3: " .$k3w6. "\n\n";
                    break;
                case 7:
                    $pronomail .= "Prono1: " .$k1w7. " - Prono2: " .$k2w7. " - Prono3: " .$k3w7. "\n\n";
                    break;
                case 8:
                    $pronomail .= "Prono1: " .$k1w8. " - Prono2: " .$k2w8. " - Prono3: " .$k3w8. "\n\n";
                    break;

            }

        }

        $pronomail .= " Veel succes! \n\n"; 
        $bericht =str_replace("\n","<br />",$pronomail); 
        echo $bericht. "<br />";

        //define the receiver of the email
        $to = $_SESSION['email'];
        //define the subject of the email
        $subject = 'Pronostiek';
        //define the message to be sent. Each line should be separated with \n
        $message = $pronomail;
        //define the headers we want passed. Note that they are separated with \r\n
        $headers = "From: info@doskobeveren.be\r\nBcc: webmaster@doskobeveren.be\r\n";
        $headers .= "Message-ID: <" . md5(uniqid(time())) . $_SERVER['SERVER_NAME']. ">\r\n";
        $headers .= "MIME-Version: 1.0\r\n";
        $headers .= "Date: ".date("D, d M Y H:i:s") . "\r\n";
        //$headers .= "Reply-To: info@mydomain.com\r\n";
        $headers .= "X-Priority: 3\r\nX-MSMail-Priority: Normal\r\n";
        $headers .= "X-Mailer: PHP/".phpversion()."\r\n";
        $headers .= "X-MimeOLE: Produced By MyDomain\r\n";
        $headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";         
        //$headers .= "Date: .date('r', $_SERVER['REQUEST_TIME'])\r\n";
        //send the email
        $mail_sent = @mail( $to, $subject, $message, $headers );
        //if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" 
        echo $mail_sent ? "Mail is verstuurd" : "Mail kon niet verstuurd worden";

?>

==========

有人能给我一个解决办法吗?谢谢。

EN

回答 3

Stack Overflow用户

发布于 2015-04-15 16:22:07

标头字段是可选的,只有当您想要定制它时才真正需要它。注释掉生成消息ID的行,它可能会传递邮件服务器的过滤系统,因为它本身将生成一个有效的消息ID。

票数 0
EN

Stack Overflow用户

发布于 2015-04-15 16:25:01

我推荐PHPMailer。它简单且易于实现。

代码语言:javascript
复制
<?php
require 'PHPMailerAutoload.php'; // you need to download the `PHPMailer` library and add that file path here. It changes where you place.

if(isset($_POST['submit'])
{

$mail = new PHPMailer;

//$mail->SMTPDebug = 3;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'user@example.com';                 // SMTP username
$mail->Password = 'secret';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                    // TCP port to connect to

$mail->From = $_POST['fromAddress'];
$mail->FromName = $_POST['fromName'];
$mail->addAddress($_POST['toAddress']);               // Name is optional
$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = $_POST['subject'];
$mail->Body    = $_POST['message'];

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
 }
}

?>


<html>
<body>

<form method="post" action="">
From address : <input type="email" name="fromAddress" /><br/>
From Name : <input type="text" name="fromName" /><br/>
To address :  <input type="email" name="toAddress" /><br/>
Subject : <input type="text" name="subject" /><br/>
Message : <input type="text" name="message" /><br/>
<input type="submit" name="submit" value="Submit" />

</form>

</body>
</html>
票数 0
EN

Stack Overflow用户

发布于 2015-04-15 18:42:02

我对我的php代码做了1次修改:

设置:

代码语言:javascript
复制
$headers = "From: info@doskobeveren.be\r\nBcc: webmaster@doskobeveren.be\r\n";

我已将其改为:

代码语言:javascript
复制
$headers = "From: info@doskobeveren.be\r\nBcc: webmaster@lucswebsite.net\r\n";

mailbox:webmaster@lucswebsite.net是我的其他邮件之一。现在,它又起作用了;没有“未发送邮件返回到发件人”邮件到达邮箱: info@doskobeveren.be。

因此,我认为One.com的邮件服务器上发生了一些变化,它阻止了在同一域的两个邮箱之间发送密件抄送。

我做了Andrew建议的更改,我注释掉了生成消息ID的行,并将Bcc更改为webmaster@doskobeveren.be,它也再次工作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29655362

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档