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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
  • douliu3831 2017-01-03 03:00
    关注

    php.ini

    SMTP=smtp.gmail.com
    smtp_port=465
    sendmail_from = YOUR_MAIL@gmail.com
    sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
    

    sendmail.ini

    smtp_server=smtp.gmail.com
    smtp_port=465
    error_logfile=error.log
    debug_logfile=debug.log
    auth_username=YOUR_MAIL@gmail.com
    auth_password=YOUR_MAIL_PASS
    force_sender=YOUR_MAIL@gmail.com
    

    php.ini extension=php_openssl.dll

    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 有人能代写linux应用吗?有偿,酬金可商量,具体要求联系我
  • ¥15 神经网络建立应力预测模型
  • ¥20 反编译一款APP手游,解密出lua脚本。
  • ¥15 改一下,代码,让代码符合要求
  • ¥15 报错问题,只有两个错误,如图片所示,i多次初始化
  • ¥15 matlab runtime 如何收费
  • ¥15 Tpad api账户 api口令
  • ¥30 ppt进度条制作,vba语言
  • ¥15 生信simpleaffy包下载
  • ¥15 在二层网络中,掩码存在包含关系即可通信