dsjfrkvn818747 2017-01-03 02:46
浏览 54
已采纳

使用xampp从gmail发送电子邮件

I already watch and read all videos and the questions related to the problem "how to send email in php from gmail using XAMPP?? " . It run but the execution in SENDMAIL.ini is not working well

img Problem #1 this pic shown, when I clicked the enter button, the localhost/ex2/here.php or the name of your php file will permanently load unless you click the X button on the cmd of sendmail.exe..

When I clicked the X button on the cmd of sendmail.exe, this message will shown on my php file img Problem #2

And this is my code in sending email from gmail:

  <?php

$message = "This message will directly POSTED to your GMAIL account";
$headers = "From: rence.samboy@gmail.com";

if(mail('rence.samboy@gmail.com', 'Example', $message, $headers))
{
    echo "Text message is sent to rence.samboy@gmail.com.....<BR/>";
}
else
{
echo "Not Work..";
}
?>

**Much appreciate if you can help me to fix my problem** :)

  • 写回答

2条回答 默认 最新

  • 普通网友 2017-01-03 02:56
    关注

    Well... for sending email, you need to set your gmail configuration first, such as protocol, smtp port, etc.

    For me... I'm using CodeIgnitor framework and this code that I've added in my controller:

    public function send_mail() { 
    
        $config = Array(
            'protocol' => 'smtp',
            'smtp_host' => 'ssl://smtp.gmail.com',
            'smtp_port' => 465, //or 587
            'smtp_timeout' => 7,
            'smtp_user' => 'xxx@gmail.com', //your gmail account
            'smtp_pass' => 'xxx', //your gmail password
            'mailtype'  => 'html', 
            'charset'   => 'iso-8859-1',
            'wordwrap' => TRUE,
            'newline' => "
    "
        );
    
            $name = $_POST["name"];
            $email = $_POST["email"];
            $message = $_POST["message"];
            $subject = $_POST["subject"];
            $phone = $_POST["phone"];
            $shipment_code = $_POST["shipment_code"];
            $array = "Phone No: ".$phone."<br>Email: ".$email."<br>Shipment Code: ".$shipment_code."<br>Message: ".$message;
    
             //Load email library 
             $this->load->library('email', $config); 
    
             $this->email->from('xxx@gmail.com');
             $this->email->to('xxx@xxx.com');
             $this->email->cc($email);
             $this->email->subject($subject); 
             $this->email->message($array); 
    
             //Send mail 
             if($this->email->send()) 
             $this->session->set_flashdata('email_sent',"<h2>Your email was sent successfully.</h2>");
             else 
             $this->session->set_flashdata('email_sent',"Error in sending Email."); 
             echo $this->email->print_debugger();
             $this->load->view('views_contactus');
    
    }
    

    If you want to see the view, then visit this.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 电脑蓝屏logfilessrtsrttrail问题
  • ¥20 关于wordpress建站遇到的问题!(语言-php)(相关搜索:云服务器)
  • ¥15 【求职】怎么找到一个周围人素质都很高不会欺负他人,并且未来月薪能够达到一万以上(技术岗)的工作?希望可以收到写有具体,可靠,已经实践过了的路径的回答?
  • ¥15 Java+vue部署版本反编译
  • ¥100 对反编译和ai熟悉的开发者。
  • ¥15 带序列特征的多输出预测模型
  • ¥15 Python 如何安装 distutils模块
  • ¥15 关于#网络#的问题:网络是从楼上引一根网线下来,接了2台傻瓜交换机,也更换了ip还是不行
  • ¥15 资源泄露软件闪退怎么解决?
  • ¥15 CCF-CSP 2023 第三题 解压缩(50%)