1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Quickly send SSL, TLS and non-secure mails with PhpMailer

Discussion in 'PHP' started by rcpsi, Mar 23, 2013.

  1. #1
    First download the latest PhpMailer (is free), and place it on your server.
    Then place this code in your php file:
    
    //SMTP send mail function
    require_once('phpmailer/class.phpmailer.php');
    // check if your path is correct, use ../ to go down one directory
    $mail = new PHPMailer();
    $mail->SMTPDebug = 1;
    $mail->IsSMTP();
    $mail->Host = "type_here_your_mail_server";
    $mail->Port = "587";
    //usually the port for TLS is 587, for SSL is 465 and non-secure is 25
    $mail->SMTPSecure = "tls";
    //TLS, SSL or  delete the line
    $mail->SMTPAuth = true;
    $mail->Username = 'your_username';
    $mail->Password = 'your_password';
    $mail->From = 'your_email';
    $mail->FromName = 'your_name';
    $mail->AddAddress($to, $name);
    $mail->Subject = 'mail_subject';
    $mail->Body = 'mail_body';
    if(!$mail->Send()) {
      echo 'Mailer error: '.$mail->ErrorInfo;
    } else {
            echo("<p>Message successfully sent!</p>");
            echo "E-mail: ", $to, "<br />";
            echo "Name: ", $name, "<br />";
            echo "Subject: ", $subject, "<br />";
            echo "Body: ", $body, "<br />";
     
        }
    
    PHP:
    In the mail body you can use \n to get to the next line.
     
    rcpsi, Mar 23, 2013 IP
    ThePHPMaster likes this.