Контактная форма PHP не отправляется по какой-либо причине - PullRequest
0 голосов
/ 20 декабря 2011

Я отредактировал простую контактную форму, загруженную из интернета, я не большой PHP-парень, поэтому я, скорее всего, сделал что-то не так.

Вот мой код:

<?php
/*
This first bit sets the email address that you want the form to be submitted to.
You will need to change this value to a valid email address that you can access.
*/
$webmaster_email = "xxxxxxxx@me.com"; /* ENTER EMAIL ADDRESS TO THE LEFT INSIDE THE QUOTES */

/*
This bit sets the URLs of the supporting pages.
If you change the names of any of the pages, you will need to change the values here.
*/
$feedback_page = "index.html";
$error_page = "index.html";
$thankyou_page = "index.html";

/*
This next bit loads the form field data into variables.
If you add a form field, you will need to add it here.
*/
$name = $_REQUEST['name'] ;
$company = $_REQUEST['company'] ;
$phone = $_REQUEST['phone'] ;
$email_address = $_REQUEST['email_address'] ;
$comments = $_REQUEST['message'] ;

/*
The following function checks for email injection.
Specifically, it checks for carriage returns - typically used by spammers to inject a CC list.
*/
function isInjected($str) {
    $injections = array('(\n+)',
    '(\r+)',
    '(\t+)',
    '(%0A+)',
    '(%0D+)',
    '(%08+)',
    '(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str)) {
    return true;
}
else {
    return false;
}
}

// If the user tries to access this script directly, redirect them to the feedback form,
if (!isset($_REQUEST['email_address'])) {
header( "Location: $feedback_page" );
}

// If the form fields are empty, redirect to the error page.
elseif (empty($email_address) || empty($comments)) {
    header( "Location: $error_page" );
}

// If email injection is detected, redirect to the error page.
elseif ( isInjected($email_address) ) {
    header( "Location: $error_page" );
}

// If we passed all previous tests, send the email then redirect to the thank you page.
else {
    mail( "$webmaster_email", "CDR-Print Enquiry",  
  "Name: $name", "Company: $company", "Phone: $phone", "From: $email_address", "Message: $comments"  );
header( "Location: $thankyou_page" );
}
?>

Ответы [ 3 ]

3 голосов
/ 20 декабря 2011

Функция Mail может принимать до 5 аргументов, в вашем случае она принимает 7, и большинство из них не имеют смысла:

mail( "$webmaster_email", "CDR-Print Enquiry", "Name: $name", "Company: $company", "Phone: $phone", "From: $email_address", "Message: $comments");

Пожалуйста, проверьте руководство по почте , чтобы увидеть, как ваш скрипт должен работать, в основном вам нужно сделать это так:

mail('person@example.com', 'My Subject', $message);
0 голосов
/ 20 декабря 2011

Это дает какую-то ошибку? Или просто не отправлять почту? Вы можете проверить, была ли функция mail успешной или нет, запустив на ней if, поскольку mail возвращает логическое значение ее успеха.

0 голосов
/ 20 декабря 2011

Ошибка в вашей почтовой функции

Это должно быть примерно так:

$message = 'Name: $name, Company: $company Phone: $phone From: $email_address Message: $comments'

mail( "$webmaster_email", "CDR-Print Enquiry", $message);

Пожалуйста, проверьте эту ссылку, чтобы вы могли лучше понять функцию почты.

...