首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >联系人表格不向Gmail发送消息

联系人表格不向Gmail发送消息
EN

Stack Overflow用户
提问于 2015-06-29 00:01:06
回答 2查看 706关注 0票数 0

拜托,我需要帮助。我的联系方式不是向我的gmail发送信息。我也检查了我的垃圾邮件,但没有收到任何信息。不知道是不是和我的代码有关。提前谢谢。我已经意识到这条信息正在进入我的godaddy中。主题是

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

消息体说

您发送的邮件包含一个错误构造的收件人地址:“来自:缺少或格式错误的本地部件(expect word或”<“”),该邮件尚未传递给任何收件人。

也请忽略我的部分代码没有添加的$ip字段。

代码语言:javascript
复制
    <?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";
    $email = "From: $email";
    $comment = "Message: $comment";
    $message = "$message" . "\n\n\n==-   Sent from the website with IP Address: " . $ip . "   -==";
    $headers = "From: $email,";
    $send_contact = mail($to,$email,$comment,$message,$headers);
    header("Location: index.php");
}
?>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-06-29 00:50:10

这应该能行。

代码语言:javascript
复制
<?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");
   }
?>

我建议您学习如何在这里使用邮件函数,http://php.net/manual/en/function.mail.php

票数 0
EN

Stack Overflow用户

发布于 2015-06-29 01:43:27

嘿早上好

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

首先,您需要从这里下载phpmailer,https://github.com/PHPMailer/PHPMailer/archive/master.zip

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

https://github.com/PHPMailer/PHPMailer

代码语言:javascript
复制
<?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';
}

第二条路。

如果你在在线模式下进行测试(有自己的域名和主机),你可以随意复制和粘贴。

不需要电话信箱。

代码语言:javascript
复制
<?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;
    }

}


?>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31106047

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档