Wednesday, January 13, 2021

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



Description




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 yourdomain.com / mail.yourdomain.com
       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->isSMTP();
$mail->Host = 'yourdomain.com'; // Can be mail.yourdomain.com
$mail->SMTPAuth = true;
$mail->Username = 'webmail@domain.com'; // 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('webmail@domain.com'); // Your host email account which you used as SMTP server
$mail->addAddress('youranyemail@email.com'); // Email Address where you want to receive emails (You can use any other email address to receive emails)


Source Codes


index.php



style.css



sendemail.php



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

    ReplyDelete
    Replies
    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.

      Delete
  2. SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
    i am geting this error when i upload on server and submit the form

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

    ReplyDelete
  4. Thank you so much working absolutely fine first got error of Authenticate issue when i allowed https://myaccount.google.com/lesssecureapps?pli=1&rapt=AEjHL4N3OX7HfyUt9W70HD_s2fCJeM8hOQHnSeaUt9W1TdjEpoqePrbbSyh2RhGZL5Dvq_bj1tl242EjppKVfFHqyiR4QHFR3g Less secure apps Link On then completed the task thank you so much

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

    ReplyDelete

Whatsapp Button works on Mobile Device only