【问题标题】:PHP Mail Sending on some webpages在某些网页上发送 PHP 邮件
【发布时间】:2013-09-10 03:49:38
【问题描述】:

此代码用于我的联系页面,它会输出一封电子邮件,我可以使用 gmail 阅读。

<?php
$message = "Sender:" . "\r\n" . $_POST["email"] . "\r\n" . "\r\n" . "Company Name:" . "\r\n" . $_POST["company"] . "\r\n" . "\r\n" .'Message:' . "\r\n" . $_POST["message"];

$to = "EMAIL ADDRESS TAKEN OUT FOR SECURITY PURPOSES, IT'S LEGIT";
$subject = $_POST["title"];
$body = $message; 

$headers = 'From:' . $_POST["email"] . "\r\n" .
    'Reply-To:'  . $_POST["email"] . "\r\n" .
    'X-Mailer: PHP/' . phpversion();


if (mail($to, $subject, $body, $headers)) {
    echo("<p class='form'>You're message was sent successfully! We'll get back to you shortly. In the mean-time... ");
} else {
echo("<p class='form'>Oops! There was an error sending your message.");
}
?>

但是,当我将此代码放入另一个页面时...

    $message = "Hey, testing this. Go to this link <a href='WEB ADDRESS HIDDEN=" .$display ."'>Activate</a>" ;

$subject = "Activate your Account";

if (mail($email, $subject, $message))
{
echo "A verification link was sent to <strong>".$email."</strong>";
}

它不发送电子邮件! $email 是我之前用来插入数据库的变量。用户输入了它。之后,我向他们发送了一封电子邮件,但它没有发送。 Mail() 返回 true,因为它也会使用正确的电子邮件地址打印文本。

这里有什么问题?有什么建议吗?

我是 php 新手,所以.. 试着像第一次学习一样说话。

谢谢!

编辑:

变量不相关。他们不说话。它们具有相同的名称,但存在于彼此没有关系的不同页面上。

【问题讨论】:

    标签: php email gmail


    【解决方案1】:

    $email 变量必须存在于两个页面上,这意味着您必须通过$_GET$_SESSION 以某种方式将其传输到第二个脚本

    在你的第一个脚本上

    // put this at the very top of the script to start a session
    <?php
    session_start();
    
    // then, do your stuff and, after you set your $email variable, se a session
    $_SESSION['email'] = $email;
    

    在你的第二个脚本上

    <?php
    session_start();
    $email = $_SESSION['email'];
    
    // do your other stuff, then send your email...
    mail($email, $subject, $message);
    

    【讨论】:

    • 变量不相关,使用一次后丢弃。我更新了主题以确保每个人都能看到它。感谢您的回复。
    • 好的。你确定gmail现在不只是慢吗?您是否尝试过在其他服务上使用其他电子邮件地址?
    【解决方案2】:

    在冒号(":") ion From, X-Mailer etc之后,应该有一个空格。

    $headers = 'From: ' . $_POST["email"] . "\r\n" .
        'Reply-To: '  . $_POST["email"] . "\r\n" .
        'X-Mailer: PHP/' . phpversion();
    

    此外,请确保“收件人”的格式正确。

    第二页上$email 的值是多少?是否设置正确?

    最后,这是在什么服务器上运行的?可能是默认的From: 电子邮件地址无效(这就是为什么第一页上的代码按预期工作的原因,因为它设置了正确的From 电子邮件地址?)。

    【讨论】:

    • 第一个代码之前工作过。第二段代码存在于不同的页面上并且不起作用。我更新它只是因为我可以。 :)
    • 好的。服务器详细信息呢?默认情况下发件人电子邮件地址是否正常,因为第二页上没有发送标题。
    猜你喜欢
    • 2016-01-05
    • 2011-07-05
    • 2015-06-15
    • 2021-08-12
    • 1970-01-01
    • 2012-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多