Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPMAILER Not sending and not giving error

I am trying to let users fill out a contact form, which will then be sent to my email. But its not working for some reason. I just get a blank page with no error message or any text and email is also not sent.

if (isset($_POST['submit']))
{
    include_once('class.phpmailer.php');

    $name = strip_tags($_POST['full_name']);
    $email = strip_tags ($_POST['email']);
    $msg = strip_tags ($_POST['description']);

    $subject = "Contact Form from DigitDevs Website";

    $mail = new PHPMailer();
    $mail->IsSMTP();
    $mail->CharSet = 'UTF-8';

    $mail->Host       = "mail.example.com"; // SMTP server example
    //$mail->SMTPDebug  = 1;                     // enables SMTP debug information (for testing)
    $mail->SMTPAuth   = true;                  // enable SMTP authentication
    $mail->Port       = 26;                    // set the SMTP port for the GMAIL server
    $mail->Username   = "[email protected]"; // SMTP account username example
    $mail->Password   = "password";        // SMTP account password example

    $mail->From = $email;
    $mail->FromName = $name;

    $mail->AddAddress('[email protected]', 'Information'); 
    $mail->AddReplyTo($email, 'Wale');

    $mail->IsHTML(true);

    $mail->Subject = $subject;

    $mail->Body    =  $msg;
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

    if(!$mail->Send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
    exit;
}
echo 'Message has been sent';
like image 554
Wale Avatar asked Jun 28 '13 12:06

Wale


People also ask

Does PHPMailer have a limit?

PHPMailer does not set any limits, nor does the mail() function, it's only ISPs like GoDaddy that do. However, they do so by blocking access to normal SMTP ports, and/or redirecting SMTP connections to their own servers ( *.

Is PHPMailer SMTP?

PHPMailer can use a non-local mail server (SMTP) if you have authentication. Further advantages include: It can print various kinds of error messages in more than 40 languages when it fails to send an email. It has integrated SMTP protocol support and authentication over SSL and TLS.


1 Answers

You need to call:

$mail = new PHPMailer(true); // with true in the parenthesis

From the documentation:

The true param means it will throw exceptions on errors, which we need to catch.

like image 79
user3670588 Avatar answered Sep 24 '22 17:09

user3670588