Joe223
Joe223

Reputation: 1

SMTP setup in PHP for HTML form

I have a website and I have created a contact form on the website, but my hosing plan does not include SMTP so I can't get messages from my contact form, is there any way to set up SMTP in the PHP form? If so here is my php, thank you for helping.

<?php

    if(isset($_POST['email'])) {



// EDIT THE 2 LINES BELOW AS REQUIRED

$email_to = "[email protected]";

$email_subject = "Your email subject line";





function died($error) {

    // your error code can go here

    echo "We are very sorry, but there were error(s) found with the form you submitted. ";

    echo "These errors appear below.<br /><br />";

    echo $error."<br /><br />";

    echo "Please go back and fix these errors.<br /><br />";

    die();

}



// validation expected data exists

if(!isset($_POST['first_name']) ||

    !isset($_POST['last_name']) ||

    !isset($_POST['email']) ||

    !isset($_POST['telephone']) ||

    !isset($_POST['comments'])) {

    died('We are sorry, but there appears to be a problem with the form you submitted.');       

}



$first_name = $_POST['first_name']; // required

$last_name = $_POST['last_name']; // required

$email_from = $_POST['email']; // required

$telephone = $_POST['telephone']; // not required

$comments = $_POST['comments']; // required
// create email headers

    $headers = 'From: '.$email_from."\r\n".

    'Reply-To: '.$email_from."\r\n" .

    'X-Mailer: PHP/' . phpversion();

    @mail($email_to, $email_subject, $email_message, $headers);  

    ?>

Upvotes: 0

Views: 88

Answers (1)

user1593330
user1593330

Reputation:

use phpmailer to use smtp . You can set your Gmail SMTP credentials to test emails are working or not to test it.

Upvotes: 1

Related Questions