首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何用php发送更长的邮件

如何用php发送更长的邮件
EN

Stack Overflow用户
提问于 2018-08-17 04:39:04
回答 1查看 49关注 0票数 0

我一直在尝试用PHP发送电子邮件,但每当消息太长时,邮件就不会被发送。

这就是我到目前为止所知道的:

代码语言:javascript
复制
$name= $_POST["name"];
$email= $_POST["email"];
$comment= $_POST["text"];

$msg= "Naam: " . $name . "\r\nEmail: " . $email . "\r\nBericht: " . $comment;

mail("test.test@live.nl", "Website", $msg);
EN

回答 1

Stack Overflow用户

发布于 2018-08-17 04:45:02

我不建议你这样做,因为电子邮件可能会收到垃圾邮件。

我建议你使用phpmailer。

我给你举个例子:

代码语言:javascript
复制
    try {



        $mail = new PHPMailer(true);          
            //Server settings
        $mail->isSMTP();       
        $mail->SMTPDebug = 0;                                 // Enable verbose debug output
        $mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers
        $mail->SMTPAuth = true;                               // Enable SMTP authentication
        $mail->Username = 'example@example.com';                 // SMTP username
        $mail->Password = 'pass';                           // SMTP password
        $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
        $mail->Port = 587;                                    // TCP port to connect to
        $mail->SMTPOptions = array(
            'ssl' => array(
                'verify_peer' => false,
                'verify_peer_name' => false,
                'allow_self_signed' => true
            )
        );

        //Recipients
        $mail->setFrom('example@example.com', 'name');

        if(is_array($this->Emails)){
            foreach($this->Emails as $email){
                $mail->addAddress($email);     // Add a recipient
            }
        }
        else{
            $mail->addAddress($this->Emails);     // Add a recipient
        }

        if(isset($this->Attachments)){

            if(is_array($this->Attachments)){
                foreach($this->Attachments as $Attachment){
                    $mail->addAttachment($Attachment);         // Add attachments
                }
            }
            else{
                $mail->addAttachment($this->Attachments);         // Add attachments
            }

        }

        //Content
        $mail->isHTML(true);                                  // Set email format to HTML
        $mail->Subject = $this->Subject;
        $mail->Body    = $this->Body;

        $mail->send();
        return true;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51885018

复制
相关文章

相似问题

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