Jump to content

Email Form Script


eleytheria

Recommended Posts

Hey All *waves* so I just created an account here. The problem I'm having is with an email contact form. I've previously used it on many other sites with success, so I'm not 100% sure why it isn't working now.

 

I have a feeling that it's because the server where this site is hosted has PHP 5, whereas the others were older. The problem is that I have no idea how to modify the script if that is in fact the issue. Any help would be appreciated.

 

The error message I am getting is:

 

Warning:  mail() [function.mail]: SMTP server response: 451 See http://pobox.com/~djb/docs/smtplf.html. in D:\Hosting\7100210\html\form_handler.php on line 71

 

An error has occurred!  Mail was not sent.

 

This is the code on line 71:

if (mail ($email_form_to, $subject, html_entity_decode ($email_body), $headers)) {

 

And this is all the code:

 

<pre>

<?php

function cleanmysql($arr,$arr2) {

foreach ($arr as $gt1=>$gt2) {

if (is_array($arr[$gt1])) {

list($arr[$gt1],$arr2[$gt1]) = cleanmysql($arr[$gt1],$arr2[$gt1]);

} else {

if (get_magic_quotes_gpc()) {

 

} else {

$gt2=mysql_escape_string($gt2);

 

}

$gt2 = htmlentities($gt2);

$arr[$gt1]=$arr2[$gt1]=$gt2;

}

}

 

return array($arr,$arr2);

}

 

function check_email ($email) {

 

if (!preg_match("/^([a-zA-Z0-9_\.-]+)@([a-zA-Z0-9\-])+\\.+([a-zA-Z0-9\-\.]{2,})+$/i", $email)) {

return FALSE;

} else {

return TRUE;

}

 

}

 

 

 

if (isset ($_POST['submit'])) {

 

list($_POST,$GLOBALS) = cleanmysql($_POST,$GLOBALS);

 

 

 

if (isset ($_POST['email_form_to']) && !empty ($_POST['email_form_to']) && check_email ($_POST['email_form_to'])) {

if (isset ($_POST['email_form_from']) && !empty ($_POST['email_form_from']) && check_email ($_POST['email_form_from'])) {

if (isset ($_POST['redirect_user_to']) && !empty ($_POST['redirect_user_to'])) {

if (isset ($_POST['email_subject']) && !empty ($_POST['email_subject'])) {

 

$email_form_to = $_POST['email_form_to'];

$email_form_from = $_POST['email_form_from'];

$redirect_user_to = $_POST['redirect_user_to'];

$email_body = '';

$headers = '';

$subject = $_POST['email_subject'];

 

foreach ($_POST as $key => $value) {

 

if ($key != 'submit' && $key != 'email_form_to' && $key != 'redirect_user_to' && $key != 'email_subject') {

 

$email_body .= "$key: $value\n";

 

}

}

 

### Send Message

 

$email_body .= "---------------------------------------\n";

$email_body .= "IP Address: " . $_SERVER['REMOTE_ADDR'];

 

$headers .= "From: $email_form_from\n";

$headers .= "X-Mailer: PHP v" . phpversion() . "\n";

$headers .= "Content-Type: text/plain; charset=iso-8859-1\n";

$headers .= "Content-Transfer-Encoding: 8bit";

 

if (mail ($email_form_to, $subject, html_entity_decode ($email_body), $headers)) {

 

echo "<meta http-equiv=\"refresh\" content=\"0;url=$redirect_user_to\">";

 

} else {

 

echo "An error has occurred!  Mail was not sent.";

 

}

 

} else {

echo 'An error has occurred - you must supply an email subject.';

}

} else {

echo 'An error has occurred - you must supply an address to forward the user to.';

}

} else {

echo 'An error has occurred - you must supply an email address!';

}

} else {

echo 'An error has occurred - you must supply an email address to send the results to. ';

}

 

}

 

?>

</pre>

Link to comment
Share on other sites

Hi,

 

Having a quick look at http://pobox.com/~djb/docs/smtplf.html it would seem to suggest that the problem is because you are using \n instead of \r\n for the new lines in the email content.  I think this may be more associated with the headers but it'll not do any harm to replace all the \n for \r\n.

 

Let me know how you get on.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.