2014-06-06 4 views
0

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

Отправить Сценарий:

<?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 = "[email protected]"; 

/* 
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 = "feedback_form.html"; 
$error_page = "error_message.html"; 
$thankyou_page = "thank_you.html"; 

/* 
This next bit loads the form field data into variables. 
If you add a form field, you will need to add it here. 
*/ 
$naam = $_REQUEST['naam'] ; 
$wedstrijd1 = $_REQUEST['wedstrijd1'] ; 
$wedstrijd2 = $_REQUEST['wedstrijd2'] ; 
$wedstrijd3 = $_REQUEST['wedstrijd3'] ; 
$wedstrijd4 = $_REQUEST['wedstrijd4'] ; 

/* 
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['naam'])) { 
header("Location: $feedback_page"); 
} 

// If the form fields are empty, redirect to the error page. 
elseif (empty($naam) || empty($wedstrijd1) || empty($wedstrijd2) || empty($wedstrijd3) || empty($wedstrijd4)) { 
header("Location: $error_page"); 
} 

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

// If we passed all previous tests, send the email then redirect to the thank you page. 
else { 
mail("$webmaster_email", "Nieuwe voorspelling ingestuurd!", 
$naam, 
$wedstrijd1, 
$wedstrijd2, 
$wedstrijd3, 
$wedstrijd4); 
header("Location: $thankyou_page"); 
} 
?> 

ответ

1

Метод почты РНР определен на manual как

почта (строка $ к, строка $ при условии, строка $ сообщение [, строка $ additional_headers [, строка $ additional_parameters]])

, отображающая к вам код, как

$ к = $ webmaster_email

$ Subject = Ньиве voorspelling ingestuurd!

$ сообщение = $ НААМ

$ additional_headers = $ wedstrijd1

$ additional_parameters = $ wedstrijd2

и я предполагаю, что Вы хотите $ wedstrijd1 и т.д., чтобы быть частью сообщения

Для этого, на мой взгляд, лучшим способом вернуть информацию из этого будет размещение всех переменных в отформатированном сообщении для отправки

$message = "Name = {$naam}\n" 
    ."Competition 1 = {$wedstrijd1}\n" 
    ."Competition 2 = {$wedstrijd2}\n" 
    ."Competition 3 = {$wedstrijd3}\n" 
    ."Competition 4 = {$wedstrijd4}\n"; 

mail($webmaster_email, "Nieuwe voorspelling ingestuurd!", $message); 

В additional_headers традиционно используется для установки подобных С, Cc, и Bcc

0

Вы злоупотребляете команду почты. Если вы посмотрите на documentation for mail, вы увидите, что теперь вы переопределяете дополнительные заголовки. Если вы не подаете ему адрес FROM в дополнительных заголовках, он не сможет отправить. Без дополнительных параметров он использует все, что находится в файле конфигурации 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 = "[email protected]"; 

/* 
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 = "feedback_form.html"; 
$error_page = "error_message.html"; 
$thankyou_page = "thank_you.html"; 

/* 
This next bit loads the form field data into variables. 
If you add a form field, you will need to add it here. 
*/ 
$naam = $_REQUEST['naam'] ; 
$wedstrijd1 = $_REQUEST['wedstrijd1'] ; 
$wedstrijd2 = $_REQUEST['wedstrijd2'] ; 
$wedstrijd3 = $_REQUEST['wedstrijd3'] ; 
$wedstrijd4 = $_REQUEST['wedstrijd4'] ; 

/* 
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['naam'])) { 
header("Location: $feedback_page"); 
} 

// If the form fields are empty, redirect to the error page. 
elseif (empty($naam) || empty($wedstrijd1) || empty($wedstrijd2) || empty($wedstrijd3) || empty($wedstrijd4)) { 
header("Location: $error_page"); 
} 

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

// If we passed all previous tests, send the email then redirect to the thank you page. 
else { 
    $message = $naan . $wedstrijd1 . $wedstrijd2 . $wedstrijd3 . $wedstrijd4; 
    if(mail("$webmaster_email", "Nieuwe voorspelling ingestuurd!", $message)) 
    { 
     header("Location: $thankyou_page"); 
    } 
    else 
    { 
     header("Location: $error_page"); 
    } 
} 
?> 
+0

Но когда я удалить все «wedstrijd» 1, 2, 3 и 4 электронная почта будет отправлять. Код, где я говорю: // Если мы прошли все предыдущие тесты, отправьте электронное письмо, а затем перенаправите страницу благодарности. еще { почты ("$ webmaster_email", "Ньив voorspelling ingestuurd!", $ НА, $ wedstrijd1, $ wedstrijd2, $ wedstrijd3, $ wedstrijd4); header ("Местоположение: $ thankyou_page"); } – change1001

+0

@ change1001 Вы отправляете его из своего дома с помощью сервера разработки? –

+0

@AJHenderson Итак, как мне исправить это? (ответ на ваше редактирование) – change1001

Смежные вопросы