Wednesday, January 13, 2021

Contact Page | With Sending Emails PHP - Using PHPMalier - PHP & Javascript


In this tutorial, you can learn how to develop a PHP contact page (contact form) to send emails (messages) using PHPMailer. This email sending contact page is tested on both localhost and Live Host Server and It's 100% Working.

If you getting any error alert like below when you run this on a live host server. There can be multiple reasons for that. If you are running this on a live host, you have to use the necessary settings in your host service. Because the settings of the host services are different from one to another. Read this.

"SMTP Error: Could not authenticate."
"SMTP Error: Could Not Connect to SMTP Host"

If you get these errors when you try on a live host. This might be helpful.

In your host > go to cpanel > Email Accounts > Webmail > Configure Mail Client

Then you can find Secure SSL/TLS Settings (Recommended).
From that settings use settings below.

● Username (Web Email Address)
● Password (Web email Password)
● Outgoing Server
       Host can be /
       SMTP Port: Can be 465/587

*you can use a Gmail or any email address to receive emails.

After you change codings it can be look like below.

$mail->Host = ''; // Can be
$mail->SMTPAuth = true;
$mail->Username = ''; // Your host email account which you want to use as SMTP server
$mail->Password = 'host email password'; // host email account password
$mail->SMTPSecure = 'ssl'; // Can be tls
$mail->Port = 465; // Can be 587

$mail->setFrom(''); // Your host email account which you used as SMTP server
$mail->addAddress(''); // Email Address where you want to receive emails (You can use any other email address to receive emails)

Source Codes




Download Source Files

We only allow you to publish relevant and respectful comments. Vulgar, hateful, or spam comments will be removed.

  1. Nice, But I get confuse how to get the code into my own php custom email sender

    1. That's exactly what I was looking for. It seems pretty nice in these tutorials but when it comes to take it into your own project, things get messed up.

  2. SMTP connect() failed.
    i am geting this error when i upload on server and submit the form

  3. 504 Gateway Time-out whats the reson behind this, give me quick answer

  4. Thank you so much working absolutely fine first got error of Authenticate issue when i allowed Less secure apps Link On then completed the task thank you so much

  5. How to fix this Maximum execution time of 120 seconds exceeded in C:\xampp\htdocs\my_project\phpmailer\SMTP.php on line 1227


Whatsapp Button works on Mobile Device only