Contact Form with SMTP

Hi @Kretschmeier,

this is what we have used for forms as external script and it worked. But we have moved to CRM Pardot now.

<?php	
	// error_reporting(E_ALL); 
	require './dmail/PHPMailer.php';
	require './dmail/Exception.php';
	require './dmail/SMTP.php';
	use PHPMailer\PHPMailer\PHPMailer;
	// date_default_timezone_set('Etc/UTC');
	// require '../vendor/autoload.php';

	$name = $_POST['name'];
	$e_mail = $_POST['e_mail'];
	$phone = $_POST['phone'];
	$company = $_POST['company'];
	$message = $_POST['message'];
	
    if(!isset($_POST['name']) ||
	!isset($_POST['e_mail']) ||
	!isset($_POST['phone']) ||
	!isset($_POST['company']) ||
	!isset($_POST['message'])) {
		echo "Please fill all fields";
		http_response_code(500);
		die();
	}


    if($_POST['name'] == "" ||
	$_POST['e_mail'] == "" ||
	$_POST['phone'] == "" ||
	$_POST['company'] == "" ||
	$_POST['message'] == "") {
		echo "Please fill all fields";
		http_response_code(500);
		die();
	}

	// Create email	
	$email_subject = "YOUR SUBJECT";
	$email_body = "You have received a new message. \n\n".
				  "Name: $name \nE_Mail: $e_mail \nPhone: $phone \nCompany: $company \nMessage: $message \n";

	$mail = new PHPMailer;
	$mail->isSMTP();
	$mail->SMTPDebug = 0;
	$mail->Host = 'smtp-mail.outlook.com';
	$mail->Port = 25;
	$mail->SMTPAuth = true;
	$mail->Username = 'YOUR USERNAME';
	$mail->Password = 'YOUR PASSWORD';
	$mail->setFrom('FROM WHOM', 'Your description');
	$mail->addReplyTo('TO WHOM', 'Your description');
	$mail->addAddress('CC email');
	//Set the subject line
	$mail->Subject = $email_subject;
	$mail->msgHTML($email_body);
	$mail->AltBody = $email_body;
	if (!$mail->send()) {
		echo 'Error Sending message';
	} else {
		echo 'Message sent!';
	}
?>

The above code needs to be placed in the form file that is created from blocs.
Just replace default content.

In addition you need this set of files to be uploaded to your hostdmail.zip (50.2 KB)

I hope this can help you.

1 Like