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条回答 默认 最新

  • duanluan033648 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

    打赏 评论

相关推荐 更多相似问题