contact form error "You must provide at least one recipient email address"

1 reply · opened Jan 17, 2017

Mmscoates29Jan 17, 2017

Hi, first of all thanks for the template it's fantastic.

I'm encountering an error with my contact form at http://www.croydonboxing.com

I get the following error message:

Email could not be sent due to some Unexpected Error. Please Try Again later.

Reason:
You must provide at least one recipient email address.

I can't see what is wrong with my sendmail.php and have tried changing various sections of it but to no avail - hopefully you can shed some light on what I am doing wrong?

Thanks in advance. php:

<?php

require_once('phpmailer/PHPMailerAutoload.php');

$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "n3plcpnl0052.prod.ams3.secureserver.net";
$mail->SMTPDebug = 0;
$mail->SMTPAuth = true;
$mail->Host = "n3plcpnl0052.prod.ams3.secureserver.net";
$mail->Port = 465;
$mail->Username = "info@croydonboxing.com";
$mail->Password = "XXXXXXXX";

if( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
if( $_POST['template-contactform-email'] != '' ) {

	$name = isset( $_POST['template-contactform-name'] ) ? $_POST['template-contactform-name'] : '';
	$email = isset( $_POST['template-contactform-email'] ) ? $_POST['template-contactform-email'] : '';
	$messagesubject = isset( $_POST['template-contactform-subject'] ) ? $_POST['template-contactform-subject'] : '';
	$message = isset( $_POST['template-contactform-message'] ) ? $_POST['template-contactform-message'] : '';

	$subject = isset($subject) ? $subject : 'New Message From Contact Form';

	$botcheck = $_POST['template-contactform-botcheck'];

$toemail = 'info@croydonboxing.com'; // Your Email Address
$toname = 'Croydon Boxing'; // Your Name

	if( $botcheck == '' ) {

		$mail-&gt;SetFrom( 'info@croydonboxing.com', 'Adam Ballard' );
		$mail-&gt;AddReplyTo( $email , $name );
		foreach( $toemails as $toemail ) {
			$mail-&gt;AddAddress( $toemail['email'] , $toemail['name'] );
		}
		$mail-&gt;Subject = $subject;

		$name = isset($name) ? "Name: $name&lt;br&gt;&lt;br&gt;" : '';
		$email = isset($email) ? "Email: $email&lt;br&gt;&lt;br&gt;" : '';
		$phone = isset($phone) ? "Phone: $phone&lt;br&gt;&lt;br&gt;" : '';
		$service = isset($service) ? "Service: $service&lt;br&gt;&lt;br&gt;" : '';
		$message = isset($message) ? "Message: $message&lt;br&gt;&lt;br&gt;" : '';

		$referrer = $_SERVER['HTTP_REFERER'] ? '&lt;br&gt;&lt;br&gt;&lt;br&gt;This Form was submitted from: ' . $_SERVER['HTTP_REFERER'] : '';

		$body = "$name $email $phone $service $message $referrer";

		// Runs only when File Field is present in the Contact Form
		if ( isset( $_FILES['template-contactform-file'] ) && $_FILES['template-contactform-file']['error'] == UPLOAD_ERR_OK ) {
			$mail-&gt;IsHTML(true);
			$mail-&gt;AddAttachment( $_FILES['template-contactform-file']['tmp_name'], $_FILES['template-contactform-file']['name'] );
		}

		// Runs only when reCaptcha is present in the Contact Form
		if( isset( $_POST['g-recaptcha-response'] ) ) {
			$recaptcha_response = $_POST['g-recaptcha-response'];
			$response = file_get_contents( "https://www.google.com/recaptcha/api/siteverify?secret=" . $recaptcha_secret . "&response=" . $recaptcha_response );

			$g_response = json_decode( $response );

			if ( $g_response-&gt;success !== true ) {
				echo '{ "alert": "error", "message": "Captcha not Validated! Please Try Again." }';
				die;
			}
		}

		$mail-&gt;MsgHTML( $body );
		$sendEmail = $mail-&gt;Send();

		if( $sendEmail == true ):
			echo '{ "alert": "success", "message": "' . $message_success . '" }';
		else:
			echo '{ "alert": "error", "message": "Email **could not** be sent due to some Unexpected Error. Please Try Again later.&lt;br /&gt;&lt;br /&gt;**Reason:**&lt;br /&gt;' . $mail-&gt;ErrorInfo . '" }';
		endif;
	} else {
		echo '{ "alert": "error", "message": "Bot **Detected**.! Clean yourself Botster.!" }';
	}
} else {
	echo '{ "alert": "error", "message": "Please **Fill up** all the Fields and Try Again." }';
}

} else {
echo '{ "alert": "error", "message": "An unexpected error occured. Please Try Again later." }';
}

?>

SSemicolon WebSTAFFJan 20, 2017

Hello,

Thanks for the Kind Words! :)

We have just checked our your Codes and the Default Codes has been changed. Please find the following code in the above code:

foreach( $toemails as $toemail ) {
$mail->AddAddress( $toemail['email'] , $toemail['name'] );
}

and replace it with:

$mail->AddAddress( $toemail , $toname );

This should definitely fix your issue. Hope this Helps!

Let us know if we can help you with anything else or if you find any further issues.

Have the same question, or something new?

Sign in to the Canvas dashboard to reply or open your own topic. Canvas owners get direct help from the SemiColonWeb team.

Reply on the dashboard