how send emails with PHPMailer?


  • | 568 points

    I usually work in xampp server but I would like work in laragon, but I can't send emails with library PHPMailer, I work very much in this library.

    not show any error.
    help me please, thank you


  • administrators
    | 87399 points

    @gabgustavo : Laragon's Mail Analyzer (Menu > Preference > Mail Sender > Test Sending Email) uses PHPMailer without any issue.
    Please give me more information so I can help.


  • | 568 points

    Thank you, I have the setting of Phpmailer similary to this link: https://stackoverflow.com/questions/16048347/send-email-using-gmail-smtp-server-through-php-mailer.
    but with more parameters. I use psr4 in the sistems.
    Message that generate:
    Laragon with authentication:
    SMTP -> ERROR: Failed to connect to server: (0)
    The following From address failed: myemail@gmail.com.
    Laragon without authentication:
    show a message with a checkbox and the message: =?UTF-8Q?AndMySubject
    xampp with or without authentication no problem to send emails

    Thank per you collaboration


  • administrators
    | 87399 points

    @gabgustavo : This code works for me:

    <?php
    require_once 'PHPMailerAutoload.php';
    $mail = new PHPMailer();
    $mail->CharSet = 'UTF-8';
    $to               = 'xxxx@gmail.com';
    $username         = 'xxxx@gmail.com';
    $password         = 'xxxx';
    echo 'Welcome to Laragon Mail Analyzer...';
    $subject          = 'Laragon Mail Analyzer: Congratulations! Your configuration is OK';
    $body             = '<p>It means you can use mail() function to send email to Internet easily with Laragon. Let\'s try:</p>
    <p style="font-weight: bold; margin: 15px;">mail(\'leokhoa@gmail.com\', \'Hi leokhoa\', \'I like Mail Sender feature.\');</p><p>Enjoy programming :)</p>' . '<div>Best wishes,</div><div>Laragon.</div>';
    
    $mail->IsSMTP();
    $mail->SMTPOptions = array(
        'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
        )
    );
    $mail->SMTPDebug  = 2;                     
    $mail->SMTPAuth   = true;                  
    $mail->SMTPSecure = 'tls';                 
    $mail->Host       = 'smtp.gmail.com';      
    $mail->Port       = 587;                   
    $mail->Username   = $username;  
    $mail->Password   = $password;            
    
    $mail->SetFrom($username, 'Blah');
    $mail->AddReplyTo($username,'Blah');
    $mail->Subject    = $subject;
    $mail->MsgHTML($body);
    $address = $to;
    $mail->AddAddress($address, 'Blah');
    if(!$mail->Send()) {
      echo 'Mailer Error: ' . $mail->ErrorInfo;
    } else {
      echo 'Message sent successfully!';
    }
    

  • | 568 points

    Hi, this is my code, in local doesn't work, I have that loads to a production server

    //method to send email
    public static function sendWeb($FromName, $Subject, $addAddress, $addAddressName, $msgHTML, $from="",$adjunto=""){
    //Create a new PHPMailer instance
    $mail = new PHPMailer;
    $mail->CharSet = 'UTF-8';
    $mail->SetLanguage('es','phpmailer/phpmailer/language/');
    //indico a la clase que use SMTP
    $mail->IsSMTP();
    //permite modo debug para ver mensajes de las cosas que van ocurriendo
    $mail->SMTPDebug = 1;

    	//Debo de hacer autenticación SMTP
    	$mail->SMTPAuth = true;
    	//$mail->SMTPSecure = "tls";
    	//$mail->SMTPSecure = "ssl";
    	// $mail->Host = "ssl://smtp.gmail.com:465";
    	$mail->Port = 587;
    	$mail->Host = "mx1.hostinger.co";
    
    	//indico un usuario / clave de usuario de gmail
    	$mail->Username = "no-replay@agrored.com.co";
    	$mail->Password = "xxxxxxx";
        if(empty($from)){
    	  	$mail->From = "no-replay@agrored.com.co";
        }else{
        	$mail->From = "$from";
        }
    
    	$mail->FromName =" $FromName";
    	$mail->Subject = $Subject. ' - ' . date('H:i:s');
    	//destinatario
    
    	$mail->addAddress("$addAddress","$addAddressName");
    	$mail->msgHTML($msgHTML);
    	//Attach an image file
    
    	//$mail->addAttachment('images/img-corporativa.jpg');
    	// if(@$adjunto['size']>0){
    	// 	$mail->addAttachment($adjunto['tmp_name'],$adjunto['name']);
    	// }
    	// echo "<pre>";
    	// dd($mail->send());
    	// echo "</pre>";
    	if($mail->send()) return true;
    	else return false;
    }

Log in to reply
 

Looks like your connection to Laragon was lost, please wait while we try to reconnect.