Contact Form doesnt work

When i´m trying to send a message with the Rapid Weaver contact plug in, i always get this message:

<?php //start the session session_start();

// Begin variables to be written out by RapidWeaver //

//set the return URL
$return_url = “…/index.html”;

//set the users email address
$email = “”;

//array of fields in form. (In the format “field_name” => “field_label”)
$form_fields = array(
“element0” => ‘Ihr Name:’,
“element1” => ‘Ihre E-Mail:’,
“element2” => ‘Betreff:’,
“element3” => ‘Nachricht:’

$required_fields = array(“element0”, “element1”, “element3”);

$mail_from_name = “element0”;
$mail_from_email = “element1”;
$mail_subject = “element2”;

//uses the email address defined above as the from email.
$send_from_users_email = false;

//sets the PHP setting ‘sendmail_from’ for use on a windows server.
$windows_server = false;

// Set up the error and success messages.
$message_success = ‘Danke, Ihre Mail wurde abgeschickt.
Ihre Anfrage wird umgehend bearbeitet.’;
$message_unset_fields = “Mit * markierte Felder müssen ausgefüllt werden.”;

// End variables to be written out by RapidWeaver //

// Check key variable from form against session key.
if ( ! isset($_POST[‘form_token’]) || $_POST[‘form_token’] !== $_SESSION[‘security_token’]) {
// Set a fixed error message if the keys don’t match.
redirect($return_url, ‘We cannot verify that you are trying to send an email from this form. Please try again.’);

// SPAM checking. If the “comment” form field has been filled out,
// send back to form asking to remove content and exit the script.
if ($_POST[‘comment’]) {
redirect($return_url, ‘Please remove content from the last textarea before submitting the form again. This is to protect against SPAM abuse.’);


$magic_quotes = (bool) get_magic_quotes_gpc();
foreach ($_POST[‘form’] as $key => $value) {
if ($magic_quotes) {
$value = stripslashes($value);
$_SESSION[‘form’][$key] = $value;


//if any of the required fields are empty
if (check_required_fields($required_fields) === false) {
//return to form with error message.
redirect($return_url, $message_unset_fields);
} else {


//check email address
if ( ! check_email($email)) unset($email);

//set mime boundry. Needed to send the email. Mixed seperates text from attachments.
$mixed_mime_boundary = ‘rms-mix-x’.md5(mt_rand()).‘x’;
//alt seperates html from plain text.
$alt_mime_boundary = ‘rms-alt-x’.md5(mt_rand()).‘x’;

//set the from address if user supplied email is invalid use form owners.
$submitted_email = ‘’;
if (isset($_SESSION[‘form’][$mail_from_email])) {
$submitted_email = $_SESSION[‘form’][$mail_from_email];

if (check_email($submitted_email) && $send_from_users_email === false) {
$from = $reply_to = $_SESSION[‘form’][$mail_from_name].’ <‘.$submitted_email.’>‘;
} else {
$from = ‘<’.$email.’>‘;
$reply_to = check_email($submitted_email) ? ‘<’.$submitted_email.’>’ : $from;

//set the email subject
$subject = ‘’;
if (isset($_SESSION[‘form’][$mail_subject])) {
$subject = $_SESSION[‘form’][$mail_subject];

//email headers
if ($windows_server === true) {
$headers = “From: $from\r\n” .
“Reply-to: $reply_to\r\n” .
"MIME-Version: 1.0\r\nContent-Type: multipart/mixed; " .
} else {
$headers = “From: $from\n” .
“Reply-to: $reply_to\n” .
"MIME-Version: 1.0\nContent-Type: multipart/mixed; " .


//Construct HTML email content, looping through each form element

//Note: When you get to a file attachment you need to use $_FILES[‘form_element’][‘name’]
//This will just output the name of the file. The files will actually be attached at the end of the message.

//Set a variable for the message content
$html_content = “\n\n” .
safe_escape_string($subject) .



//construct a plain text version of the email.
$text_content = ‘’;

//build a message from the reply for both HTML and text in one loop.
foreach ($form_fields as $field => $label) {
$html_content .= ‘’ . safe_escape_string($label) . ' ';
$text_content .= "$label ";
if (isset($_FILES[$field])) {
$string = (isset($_FILES[$field][‘name’])) ? $_FILES[$field][‘name’] : ‘’;
} else {
$string = (isset($_SESSION[‘form’][$field])) ? $_SESSION[‘form’][$field] : ‘’;
$html_content .= nl2br(safe_escape_string($string)) . “

$text_content .= “$string\n\n”;

//close the HTML content.
$html_content .= “



//Now we combine both HTML and plain text version of the email into one.
//Creating the message body which contains a Plain text version and an HTML version,
//users email client will decide which version to display
$message = “\r\n–$mixed_mime_boundary\r\n” .
“Content-Type: multipart/alternative; boundary=$alt_mime_boundary\r\n\r\n” .
“–$alt_mime_boundary\r\n” .
“Content-Type: text/plain; charset=UTF-8; format=flowed\r\n” .
“Content-Transfer-Encoding: Quoted-printable\r\n\r\n” .
“$text_content\r\n\r\n” .
“–$alt_mime_boundary\r\n” .
“Content-Type: text/html; charset=UTF-8\r\n” .
“Content-Transfer-Encoding: Quoted-printable\r\n\r\n” .
“$html_content\r\n\r\n” .
“–$alt_mime_boundary–\r\n\r\n” .


//loop through the $_FILES global array and add each attachment to the form.
if (isset($_FILES)) {
foreach ($_FILES as $attachment) {
$filename = $attachment[‘name’];

  	//if the file has been uploaded
  	if ($attachment['error'] === UPLOAD_ERR_OK && is_uploaded_file($attachment['tmp_name'])) {
  		$file = fopen($attachment['tmp_name'],'rb');
  		$data = fread($file,filesize($attachment['tmp_name']));
  		$data = chunk_split(base64_encode($data));
  		$message .= "\r\nContent-Type: application/octet-stream; name=\"$filename\"" .
  		"\r\nContent-Disposition: attachment; filename=\"$filename\"" .
  		"\r\nContent-Transfer-Encoding: base64\r\n\r\n$data\r\n\r\n--$mixed_mime_boundary";
  	} else if ($attachment['error'] !== UPLOAD_ERR_NO_FILE) {
  		//try to provide a useful error message determined from the error code.
  		switch ($attachment['error']) {
  				$error = "File $filename exceeds the " . ini_get('upload_max_filesize') . 'B limit for the server.';
  				$error = "Only part of the file $filename could be uploaded, please try again.";
  				$error = "There has been an error attaching the file $filename, please try again.";
  		redirect($return_url, $error);


//finish off message
$message .= ‘–’;

//for windows users.
if ($windows_server === true) {
ini_set(‘sendmail_from’, $email);

//if the mail sending works
if (@mail($email, $subject, $message, $headers)) {
//set the success message
$notice = $message_success;
} else {
$notice = “I’m sorry, there seems to have been an error trying to send your email. Please try again.”;

//redirect to the form
redirect($return_url, $notice);


// Redirects back to the form, an optional session message can be defined.
function redirect($url, $message = NULL) {
if ($message) {
$_SESSION[‘formMessage’] = $message;
header('Location: ’ . $url);

// Function to escape data inputted from users. This is to protect against embedding
// of malicious code being inserted into the HTML email.
// Sample code: safe_escape_string($_POST[‘form_field’])
function safe_escape_string($string) {
return htmlspecialchars($string, ENT_QUOTES);

// Function to check the validity of email address.
function check_email($email) {
return (bool) preg_match(‘/^([a-z0-9_]|-|.)+@(([a-z0-9_]|-)+.)+[a-z]{2,}$/i’, $email);

// Function to check the required fields are filled in.
function check_required_fields($required_fields) {
foreach ($required_fields as $field) {
if (( ! isset($_SESSION[‘form’][$field]) || empty($_SESSION[‘form’][$field])) &&
( ! isset($_FILES[$field]) || empty($_FILES[$field][‘name’]))) {
return false;
return true;

I hope someone can help me to fix this problem. And sorry for my bad english :joy:

@vali1860 This is usually due to a web host not supporting the latest versions of PHP. Can you check with your web host to confirm their support (or lack of)?

Also, the contact form will not function until published on a server - it will not work in preview mode.

I don’t think you have set the page type to php.

I have forgotten to say that i have not published it :sweat_smile: So it is normal that the contact form doesnt work in preview mode? And how can i chance the page type to php?
Thanks for your help!

You must publish a php page for it to work. To change the page type, go to the page inspector > general settings > filename make sure it is index.php

It is normal, that the contact form does not work in preview mode. Yes.
You must use MAMP or another server solution to test this. Or publish your site and all is ok.

This contact form is automatically a php file. You need not to change anything.

I have a problem with sending messages from form, messages sent but never come to my email (Google)
It seems like there some mistake in code of mailer??
Can you help me??

Below I have received:
2016-01-14T11:40:23+03:00 vh40 exim[99737]: 2016-01-14 11:40:23 1aJdSB-000Pwf-SW < U=seawhale P=local S=26098
2016-01-14T11:40:24+03:00 vh40 exim[99740]: 2016-01-14 11:40:24 1aJdSB-000Pwf-SW ** myemail R=dnslookup T=remote_smtp X=TLS1.2:RSA_AES_128_CBC_SHA1:128: SMTP error from remote mail server after end of data: host []: 550-5.7.1 Unauthenticated email from is not accepted due to domain’s\n550-5.7.1 DMARC policy. Please contact administrator of domain if\n550-5.7.1 this was a legitimate mail. Please visit\n550-5.7.1 to learn about DMARC\n550 5.7.1 initiative. v13si2686402lfd.153 - gsmtp

I have this same problem, but none of the ‘solutions’ listed here make any difference.

I use the same plugin on the same server for another website with no problem. It is php. It has been saved and published with no errors.

I get this error on the page when I try to use it; “We cannot verify that you are trying to send an email from this form. Please try again.”

any help?