Php 联系人表单未向Gmail发送消息

Php 联系人表单未向Gmail发送消息,php,html,forms,email,post,Php,Html,Forms,Email,Post,拜托,我需要帮助。我的联系方式没有向我的gmail发送消息。我已经检查了我的垃圾邮件也没有来。不确定这是否与我的代码有关。提前谢谢。我已经意识到这个信息正在进入我的godaddy cpanel。主题是 邮件失败-收件人地址格式错误 消息正文说 您发送的邮件包含构造不正确的收件人地址: 发件人:缺少或格式不正确的本地部分(除word或“外),这应该可以工作 <?php $emailErr = ""; $commentErr = ""; if(isset($_POST[

拜托,我需要帮助。我的联系方式没有向我的gmail发送消息。我已经检查了我的垃圾邮件也没有来。不确定这是否与我的代码有关。提前谢谢。我已经意识到这个信息正在进入我的godaddy cpanel。主题是

邮件失败-收件人地址格式错误

消息正文说

您发送的邮件包含构造不正确的收件人地址: 发件人:缺少或格式不正确的本地部分(除word或“外),这应该可以工作

<?php
    $emailErr = "";
    $commentErr = "";
    if(isset($_POST['submit'])){

        //declares variable
        $email = $_POST['email'];
        $comment = $_POST['comment'];

        if(empty($_POST['email'])){
           $emailErr = "Please enter your email";
        }
        if(empty($_POST['comment'])){
           $commentErr = "comment field can't be empty";
        }
     }

    if(!empty($_POST['email']) && !empty($_POST['comment'])){
        // Send the email
        $to = "myname@gmail.com";
        $title = "Message from my website";

        $message = "Comment: {$comment}" . "\r\n";
        $message .= "Sent from the website with IP Address: {$ip}" . "\r\n";

        $headers = "From: " . strip_tags($email) . "\r\n";
        $headers .= "Reply-To: ". strip_tags($email) . "\r\n";
        $headers .= "MIME-Version: 1.0\r\n";
        $headers .= "Content-type:text/plain;charset=UTF-8" . "\r\n";
        mail($to,$title,$message,$headers);

        header("Location: index.php");
   }
?>
你好,早上好

如果您在脱机模式下工作,可能需要phpmailer

<?php

$error = [];

$receipientName="Fido";
$receipientEmail ="receipientmail.gmail.com";
$ccEmail ="";

//declares variable
if(isset($_POST['name'])) $name = $_POST['name'];
else $name = "";

if(isset($_POST['email'])) $email = $_POST['email'];
else $email = "";



function send_mail($myname, $myemail, $contactname, $contactemail, $subject, $message) {


    $headers = "MIME-Version: 1.0\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\n";
    $headers .= "X-Priority: 1\n";
    $headers .= "X-MSMail-Priority: High\n";
    $headers .= "X-Mailer: php\n";
    $headers .= "From: \"".$myname."\" <".$myemail.">\r\n";
    return(mail("\"".$contactname."\" <".$contactemail.">", $subject, $message, $headers));
}

if(isset($Submit) && $Submit=="Go") {

     $emailContent ='';


    $sent=send_mail($name, "yourmailname.gmail.com", "Fido", $receipientEmail, "Testing", $emailContent);
    if($sent) {
      echo $emailContent;

        header('Location: contact.php');
    }else{
        echo "Failed";
        exit;
    }

}


?>
首先,您需要从这里下载phpmailer

然后粘贴到你的文件夹中。如果我的编码没有清除你,你可以从



$comment=$\u POST['comment'];
这不是一个单引号,而是一个MS智能引号。您的代码中分散了这些引号。请全部更正,打开错误报告。您真的是用word编写代码吗?请查看from标头it Errorplus
然后查看
$headers=“from:$email,“;
许多语法错误您在邮件函数中也使用了5个参数。谢谢大家的贡献。@OlaitanMayowa-您给我的代码完成了任务。非常感谢。
<?php
require 'PHPMailerAutoload.php'; // Your Path

$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';                 // Your mail 
$mail->Password = 'secret';                           // Your mail password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;     

$mail->From = 'from@example.com';
$mail->FromName = 'Mailer';
$mail->addAddress('joe@example.net', 'Joe User');     // Add a recipient
$mail->addAddress('ellen@example.com');               // Name is optional
$mail->addReplyTo('info@example.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');

$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$mail->isHTML(true);                                  // Set email format to HTML



$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

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

$error = [];

$receipientName="Fido";
$receipientEmail ="receipientmail.gmail.com";
$ccEmail ="";

//declares variable
if(isset($_POST['name'])) $name = $_POST['name'];
else $name = "";

if(isset($_POST['email'])) $email = $_POST['email'];
else $email = "";



function send_mail($myname, $myemail, $contactname, $contactemail, $subject, $message) {


    $headers = "MIME-Version: 1.0\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\n";
    $headers .= "X-Priority: 1\n";
    $headers .= "X-MSMail-Priority: High\n";
    $headers .= "X-Mailer: php\n";
    $headers .= "From: \"".$myname."\" <".$myemail.">\r\n";
    return(mail("\"".$contactname."\" <".$contactemail.">", $subject, $message, $headers));
}

if(isset($Submit) && $Submit=="Go") {

     $emailContent ='';


    $sent=send_mail($name, "yourmailname.gmail.com", "Fido", $receipientEmail, "Testing", $emailContent);
    if($sent) {
      echo $emailContent;

        header('Location: contact.php');
    }else{
        echo "Failed";
        exit;
    }

}


?>