首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >PHP邮件功能无法完成电子邮件的发送。

PHP邮件功能无法完成电子邮件的发送。
EN

Stack Overflow用户
提问于 2018-06-06 08:44:19
回答 2查看 0关注 0票数 0
<?php
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $from = 'From: yoursite.com'; 
    $to = 'contact@yoursite.com'; 
    $subject = 'Customer Inquiry';
    $body = "From: $name\n E-Mail: $email\n Message:\n $message";

    if ($_POST['submit']) {
        if (mail ($to, $subject, $body, $from)) { 
            echo '<p>Your message has been sent!</p>';
        } else { 
            echo '<p>Something went wrong, go back and try again!</p>'; 
        }
    }
?>
EN

回答 2

Stack Overflow用户

发布于 2018-06-06 17:09:59

在邮件功能中添加邮件标题

$header = "From: noreply@example.com\r\n"; 
$header.= "MIME-Version: 1.0\r\n"; 
$header.= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 
$header.= "X-Priority: 1\r\n"; 

$status = mail($to, $subject, $message, $header);

if($status)
{ 
    echo '<p>Your mail has been sent!</p>';
} else { 
    echo '<p>Something went wrong, Please try again!</p>'; 
}
票数 0
EN

Stack Overflow用户

发布于 2018-06-06 18:17:14

可以使用codeigniter的配置电子邮件,例如使用smtp(简单方法):

$config = Array(
        'protocol' => 'smtp',
        'smtp_host' => 'mail.domain.com', //your smtp host
        'smtp_port' => 26, //default port smtp
        'smtp_user' => 'name@domain.com',
        'smtp_pass' => 'password',
        'mailtype' => 'html',
        'charset' => 'iso-8859-1',
        'wordwrap' => TRUE
);
$message = 'Your msg';
$this->load->library('email', $config);
$this->email->from('name@domain.com', 'Title');
$this->email->to('emaildestination@domain.com');
$this->email->subject('Header');
$this->email->message($message);

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

https://stackoverflow.com/questions/-100004777

复制
相关文章

相似问题

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