繁体   English   中英

电子邮件表格未发送“发件人电子邮件”

[英]E-mail form not sending 'sender email'

我正在使用在教程中找到的联系表单脚本,并且工作正常。 主题和邮件联系会通过,但发件人电子邮件不会。 发件人名称和电子邮件未通过。 当我检查从表单收到的电子邮件时,收件箱中显示“未知发件人”,而当我查看邮件时则说它是通过主机发送的。

谁能看到我在这方面出了问题吗? 我在联系表格方面经验不足,需要在客户网站上尽快完成。

表单的HTML在这里:

<form action="#" id="form" method="post" name="form">
   <input name="vname" placeholder="Your Name" type="text" value="">
    <input name="vemail" placeholder="Your Email" type="text" value="">
   <input name="sub" placeholder="Subject" type="text" value="">
   <label>Your Suggestion/Feedback</label>
   <textarea name="msg" placeholder="Type your text here...">
    </textarea>
    <input id="send" name="submit" type="submit" value="Send Feedback">
</form>
<h3><?php include "secure_email_code.php" ?>
</h3>

此处的PHP代码:

<?php
if(isset($_POST["submit"])){
    // Checking For Blank Fields..
    if($_POST["vname"]=="" || $_POST["vemail"]=="" || 
       $_POST["sub"]=="" || $_POST["msg"]=="")
    {
        echo "Fill All Fields..";
    }else{
        // Check if the "Sender's Email" input field is filled out
        $email=$_POST['vemail'];
        // Sanitize E-mail Address
        $email =filter_var($email, FILTER_SANITIZE_EMAIL);
        // Validate E-mail Address    
        $email= filter_var($email, FILTER_VALIDATE_EMAIL);
        if (!$email){
            echo "Don't forget to include your email adress! Otherwise we can't get back to you.";
        }
        else{
            $subject = $_POST['sub'];
            $message = $_POST['msg'];
            $headers = 'From:'. $email2 . "\r\n"; // Sender's Email
            $headers .= 'Cc:'. $email2 . "\r\n"; // Carbon copy to Sender
            // Message lines should not exceed 70 characters (PHP rule), so wrap it
            $message = wordwrap($message, 70);
            // Send Mail By PHP Mail Function
            mail("marc@example.com", $subject, $message, $headers);
            echo "Thanks for getting in touch! We'll get back to you ASAP.";
        }
    }
}
?>

如果我从条目中使用诸如email@provider.com之类的标题对标题进行硬编码,则发送的邮件将其替换为@webhost.com例如:我输入me@gmail.com ,发送的电子邮件说它来自于me@webhost.com我的提供者有问题吗?

目前的代码:

<?php
if(isset($_POST["submit"])){
// Checking For Blank Fields..
if($_POST["vname"]==""||$_POST["vemail"]==""||$_POST["sub"]==""||$_POST["msg"]==""){
echo "Fill All Fields.";
}else{
// Check if the "Sender's Email" input field is filled out
$email=$_POST['vemail'];
// Sanitize E-mail Address
$email =filter_var($email, FILTER_SANITIZE_EMAIL);
// Validate E-mail Address
$email= filter_var($email, FILTER_VALIDATE_EMAIL);
if (!$email){
echo "Don't forget to include your email adress! Otherwise we can't get back to you.";
}
else{
$subject = $_POST['sub'];
$message = $_POST['msg'];
$headers =  'From:' . 'Ross@gmail.com' . "\r\n"; // Sender's Email
$headers .= 'Cc: chad' . "\r\n"; // Carbon copy to Sender
$from = $headers;
// Message lines should not exceed 70 characters (PHP rule), so wrap it
$message = wordwrap($message, 70);
// Send Mail By PHP Mail Function
mail("marc.murray.92@gmail.com", $subject, $message, $headers);
echo "Thanks for getting in touch! We'll get back to you ASAP.";
}
}
}
?>

尝试phpMailer: https : //github.com/PHPMailer/PHPMailer

<?php
$contact = "email@gmail.com";
    $msg = ob_get_clean();
    $subject = "example";
    $mail = new PHPMailer();


    $mail->CharSet = 'UTF-8';
    $mail->IsSMTP();
    //$mail->SMTPDebug = 2; this will show you a debug
    $mail->SMTPAuth = true;           // enable SMTP authentication
    $mail->SMTPSecure = "ssl";        // sets the prefix to the servier
    $mail->Host = "smtp.gmail.com";   // sets GMAIL as the SMTP server
    $mail->Port = 465;                // set the SMTP port
    $mail->IsHTML(true);
    //$mail->SMTPDebug = 2;
    //$mail->Timeout = 15;
    $mail->Username = "example@gmail.com";  // GMAIL username
    $mail->Password = "yourpassword";            // GMAIL password

    $mail->SetFrom = "example@gmail.com";
    $mail->Subject = $subject;
    $mail->AltBody = "your client doesn't accept HTML";
    $mail->Body = $msg;

    $mail->AddAddress($contact, $subject);
    //$mail->MsgHTML($msg);
    // send as HTML
    if (!$mail->Send()) {
        echo "Mail Error" . $mail->ErrorInfo;
    };
    //Pretty error messages from PHPMailer
    unset($mail);
}

尝试这个:

  <?php
if(isset($_POST["submit"])){
// Checking For Blank Fields..
if($_POST["vname"]==""||$_POST["vemail"]==""||$_POST["sub"]==""||$_POST["msg"]==""){
echo "Fill All Fields..";
}else{
// Check if the "Sender's Email" input field is filled out
$email=$_POST['vemail'];
// Sanitize E-mail Address
$email = filter_var($email, FILTER_SANITIZE_EMAIL);
// Validate E-mail Address

if (filter_var($email, FILTER_VALIDATE_EMAIL) ){
echo "Don't forget to include your email adress! Otherwise we can't get back to you.";
}
else{
$subject = $_POST['sub'];
$message = $_POST['msg'];
$headers = 'From:'. $email . "\r\n"; // Sender's Email
$headers .= 'Cc:'. $email . "\r\n"; // Carbon copy to Sender
// Message lines should not exceed 70 characters (PHP rule), so wrap it
$message = wordwrap($message, 70);
// Send Mail By PHP Mail Function
mail("marc@example.com", $subject, $message, $headers);
echo "Thanks for getting in touch! We'll get back to you ASAP.";
}
}
}
?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM