How to configure PHP to send e-mail?

后端 未结 8 1670
星月不相逢
星月不相逢 2020-12-10 07:12

I need to send mail to the users of my website using php script. I have tried using mail function in php.
My code is as follows:

  $to = \"myweb@gmail.co         


        
8条回答
  •  一生所求
    2020-12-10 07:24

    Use PHPMailer instead: https://github.com/PHPMailer/PHPMailer

    How to use it:

    require('./PHPMailer/class.phpmailer.php');
    $mail=new PHPMailer();
    $mail->CharSet = 'UTF-8';
    
    $body = 'This is the message';
    
    $mail->IsSMTP();
    $mail->Host       = 'smtp.gmail.com';
    
    $mail->SMTPSecure = 'tls';
    $mail->Port       = 587;
    $mail->SMTPDebug  = 1;
    $mail->SMTPAuth   = true;
    
    $mail->Username   = 'me.sender@gmail.com';
    $mail->Password   = '123!@#';
    
    $mail->SetFrom('me.sender@gmail.com', $name);
    $mail->AddReplyTo('no-reply@mycomp.com','no-reply');
    $mail->Subject    = 'subject';
    $mail->MsgHTML($body);
    
    $mail->AddAddress('abc1@gmail.com', 'title1');
    $mail->AddAddress('abc2@gmail.com', 'title2'); /* ... */
    
    $mail->AddAttachment($fileName);
    $mail->send();
    

提交回复
热议问题