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条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!