【问题标题】:How can I modfy this send.php $mail call to include the $phone paramerter如何修改此 send.php $mail 调用以包含 $phone 参数
【发布时间】:2012-03-23 04:45:15
【问题描述】:

如何将我添加的电话号码参数放入此 php 脚本发送的电子邮件正文中?:

$post = (!empty($_POST)) ? true : false;

if($post)
{
    $name    = stripslashes($_POST['name']);
    $email   = trim($_POST['email']);
    $phone   = trim($_POST['phone']);
    $subject = trim($_POST['subject']);
    $message = stripslashes($_POST['message']);

    $error = '';

    // Check name
    if(!$name)
        $error .= 'Name required! ';

    // Check email
    if(!$email)
        $error .= 'E-mail required! ';

    if($email && !ValidateEmail($email))
        $error .= 'E-mail address is not valid! ';

    // Check phone
    if(!$phone)
        $error .= 'Phone number required! ';


    // Check message
    if(!$message)
        $error .= "Please enter your message!";

    if(!$error)
    {
        $mail = mail(WEBMASTER_EMAIL, $subject, $message,
             "From: ".$name." <".$email.">\r\n"
            ."Reply-To: ".$email."\r\n"
            ."X-Mailer: PHP/" . phpversion());

        if($mail)
            echo 'OK';
    }
    else
        echo '<div class="errormsg">'.$error.'</div>';
}

我已将 $phone 添加到 $post 部分,在我的表单中创建了字段,现在我只需要在收到的电子邮件中返回内容即可。非常感谢任何提示。

【问题讨论】:

  • 如果您自己编写了这段代码,您就已经知道如何在电子邮件中添加额外的字段。请注意,此代码容易受到电子邮件标头注入的影响,并且可能被垃圾邮件发送者破坏。

标签: php send


【解决方案1】:

如果我正确理解你想要什么,你需要这样的东西:

$message = "Phone: $phone\r\n" . $message;

之前

$mail = mail(WEBMASTER_EMAIL, $subject, $message,
         "From: ".$name." <".$email.">\r\n"
        ."Reply-To: ".$email."\r\n"
        ."X-Mailer: PHP/" . phpversion());

【讨论】:

  • 感谢您的帮助。我这样做了,它按预期工作。但是,我创建了一个名为 send2.php 的重复 php 文件并相应地修改了操作,但我的表单似乎继续调用原始 send.php 文件。任何想法为什么?确定这是一个简单的错误。
  • 可能是您的浏览器正在使用缓存中的旧 HTML 页面。尝试清除浏览器的缓存,或调用 HTML 页面,并在查询字符串中附加一些内容 (yourserver/form.html?something)
猜你喜欢
  • 1970-01-01
  • 2021-06-03
  • 1970-01-01
  • 2023-01-26
  • 2013-08-08
  • 2014-07-26
  • 1970-01-01
  • 2012-11-13
  • 1970-01-01
相关资源
最近更新 更多