Contact form getting errors

I have 2 websites both using the same contact.php form, but get two different errors when customers submit the forms. I still receive the info from the form, but the client receives errors after submission.

Here are the sites with the forms:
http://plusav.partycinemas.com/#filter=.contact

http://videodanceparty.ca/contact.html

Any help would be great… seems like an easy fix, but I’m not catching it.

programming questions should include the errors you get and the relevant code. Without that it’s unnecessary hard to answer questions.

On the AV site client gets: else { ?>

Where it should show message such as thank you for your submission etc…

on the Videodance site they get the same thing - else { ?> - and a message failed popup window.

here’s the code:

<?php $field_name = $_POST['name']; $field_email = $_POST['email']; $field_Phone = $_POST['Phone']; $field_message = $_POST['message']; $body_message = 'From: '.$field_name."\n"; $body_message = 'email: '.$field_email."\n"; $body_message = 'Phone: '.$field_Phone."\n"; $body_message = 'message: '.$field_message; $headers = 'From: '.$field_email."\r\n"; $headers = 'Reply-To: '.$field_email."\r\n"; require_once "Mail.php"; $from = "<$field_email>"; $to = ""; $subject = "Video Dance Party Inquiry"; $body = "***************************\n\n Name: $field_name \n\n E-mail: $field_email \n\n Phone: $field_Phone \n\n\n Message: $field_message \n"; $host = "smtp.partycinemas.com"; $username = "xxxxxxxx"; $password = "xxxxxxx"; $headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject, 'Phone' => $field_Phone); $smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password)); $mail = $smtp->send($to, $headers, $body); ?>
<script language="javascript" type="text/javascript">
	alert('Thank you for your inquiry. We will contact you shortly!');
	window.location = 'index.html';
</script>

else { ?>

<?php ?>

Missing a php tag and an ‘if’…

Also i wouldn’t bother jumping in and out of php, just do the lot in php.
Try this:
[php]

<?php if ($mail = $smtp->send($to, $headers, $body)) { echo ''; } else { echo ''; } [/php] Red ;)

as in: ?>

Have a look in the top code i posted, there are comments where stuff is missing.
Compare to the bottom code i posted where it’s re-written - minus the closing ?> i missed :-[ #irony :slight_smile:

I used your suggested code and both sites work (thank you!) for sending…well, one does.

for this site: http://plusav.partycinemas.com/#filter=.contact

the reason I am using the same php file on both pages is my hosting company said: you can not use the PHP mail function as it does not support authenticated SMTP.

I copied the video dance php to use on the plus av contact page… after sending on the original plusav contact form php the area where you enter your details would cover over and show success or errors. …since switching to the video dance version, the form sends, but the client has no confirmation that anything has been sent as it doens’t operate like the video dance one that give a pop up window. (the content doesn’t get covered and no message is given… all the entered info just stays there even though it’s sent)

Hope this makes sense. Here is the original php code from the template that does not work on my server:

[php]<?php

if(!$_POST) exit;

function tommus_email_validate($email) { return filter_var($email, FILTER_VALIDATE_EMAIL) && preg_match(’/@.+./’, $email); }

$name = $_POST[‘name’]; $email = $_POST[‘email’]; $comments = $_POST[‘comments’];

if(trim($name) == ‘’) {

exit('<div class="error_message">Attention! You must enter your name.</div>');

} else if(trim($name) == ‘Name’) {

exit('<div class="error_message">Attention! You must enter your name.</div>');

} else if(trim($email) == ‘’) {

exit('<div class="error_message">Attention! Please enter a valid email address.</div>');

} else if(!tommus_email_validate($email)) {

exit('<div class="error_message">Attention! You have entered an invalid e-mail address.</div>');

} else if(trim($comments) == ‘Comment’) {

exit('<div class="error_message">Attention! Please enter your message.</div>');

} else if(trim($comments) == ‘’) {

exit('<div class="error_message">Attention! Please enter your message.</div>');

} if(get_magic_quotes_gpc()) { $comments = stripslashes($comments); }

$address = ‘[email protected]’;

$e_subject = 'You’ve been contacted by ’ . $name . ‘.’;

$e_body = “You have been contacted by $name from your contact form, their additional message is as follows.” . “\r\n” . “\r\n”;

$e_content = “”$comments"" . “\r\n” . “\r\n”;

$e_reply = “You can contact $name via email, $email”;

$msg = wordwrap( $e_body . $e_content . $e_reply, 70 );

$headers = “From: $email” . “\r\n”;

$headers .= “Reply-To: $email” . “\r\n”;

$headers .= “MIME-Version: 1.0” . “\r\n”;

$headers .= “Content-type: text/plain; charset=utf-8” . “\r\n”;

$headers .= “Content-Transfer-Encoding: quoted-printable” . “\r\n”;

if(mail($address, $e_subject, $msg, $headers)) { echo “

Email Sent Successfully.

Thank you $name, your message has been submitted to us.

”; }[/php]

I have rewritten the code you posted, making it much less cluttered and got rid of half the ifelse’s

[php]
if(!$_POST) exit;

function tommus_email_validate($email) {
return filter_var($email, FILTER_VALIDATE_EMAIL);
}

$name = trim($_POST[‘name’]);
$email = trim($_POST[‘email’]);
$comments = get_magic_quotes_gpc() ? stripslashes(trim($_POST[‘comments’])) : trim($_POST[‘comments’]);

if(empty($name) || strtolower($name) == ‘name’) {
exit(‘

Attention! You must enter your name.
’);
}
if(empty($email) || !tommus_email_validate($email)) {
exit(‘
Attention! Please enter a valid email address.
’);
}
if(empty($comments) || strtolower($comments) == ‘Comment’) {
exit(‘
Attention! Please enter your message.
’);
}

$address = ‘[email protected]’;
$subject = 'You’ve been contacted by ’ . $name . “\r\n”;
$message = “You have been contacted by $name from your contact form, their additional message is as follows.\r\n\r\n”;
$message .= $comments . “\r\n\r\n”;
$message .= “You can contact $name via email, $email\r\n”;
$msg = wordwrap($message, 70);

$headers = “From: $email” . “\r\n”;
$headers .= “Reply-To: $email” . “\r\n”;
$headers .= “MIME-Version: 1.0” . “\r\n”;
#$headers .= “Content-type: text/plain; charset=utf-8” . “\r\n”; // use for plain text emails
$headers .= “Content-type: text/html; charset=utf-8” . “\r\n”; // use for html emails
$headers .= “Content-Transfer-Encoding: quoted-printable” . “\r\n”;

if(mail($address, $subject, $msg, $headers)) {
echo "


Email Sent Successfully.


Thank you $name, your message has been submitted to us.



";
}
else {
echo ‘Message not sent!’;
}
[/php]

Note: I haven’t tested this code but it looks ok.
Let me know how you get on.
Red :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service