php邮件没有收到邮件

时间:2016-04-01 06:53:50

标签: php html email email-integration email-validation

我没有收到表单字段中的文本。我做错了什么?

<?php
$newsletter_email = $_POST['newsletter_email'];
$to = "gb@gyde.asia";
$subject = "Subscription for Newsletter";
$headers = "From: $to";
mail ($to, $subject, " E-mail: " . $newsletter_email, $headers);
if(mail ($to, $subject, " E-mail: " . $newsletter_email, $headers )){ 
echo "Mail did its job..."; } else { echo "Oops, something went South!";  }
?>

HTML

    <div id="newsletter" class="form-wrap"> 
        <form action="process.php" method="post" id="newsletter-form"> 
            <input type="text" name="newsletter_email" id="newsletter_email" required class="feedback-input" maxlength="30" placeholder="Email" /> 
            <input type="submit" name="newsletter_submit" id="newsletter_submit" value="Subscribe" class="button-blue"/> 
        </form> 
    </div> 

2 个答案:

答案 0 :(得分:0)

您的脚本很好,但您发送邮件两次。 在发送之前检查POST是否有要发送的消息。 改变如下:

$newsletter_email = $_POST['newsletter_email'];
if($newsletter_email != ""){
    $to = "gb@gyde.asia";
    $subject = "Subscription for Newsletter";
    $headers = "From: $to";
    if(mail ($to, $subject, " E-mail: " . $newsletter_email, $headers ))
    { 
         echo "Mail did its job..."; 
    } 
    else 
    { 
         echo "Oops, something went South!"; 
    }
}

<强> N.B 即可。检查您的垃圾邮件箱,如 Hanky Panky

答案 1 :(得分:0)

有时邮件功能不支持您的服务器。所以邮件无法到达。

有一个解决方案请使用SMTP邮件。

<?php
    ini_set("SMTP", "aspmx.l.google.com");
    ini_set("sendmail_from", "YOURMAIL@gmail.com");

    $message = "The mail message was sent with the following mail setting:\r\nSMTP = aspmx.l.google.com\r\nsmtp_port = 25\r\nsendmail_from = YourMail@address.com";

    $headers = "From: YOURMAIL@gmail.com";


    mail("Sending@provider.com", "Testing", $message, $headers);
    echo "Check your email now....<BR/>";
?>