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 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分