...

View Full Version : mail function not working



BroChris
02-02-2007, 03:20 PM
I can't get my form on this page (http://www.parklandbaptistchurch.org/contact.html) to actually send email.


<?php

if(($_GET['action'])=='send'){
$message=$_POST['message'];
if(($message != "") && ($message != 'Message')){
$realname=$_POST['realname'];
if($realname!=''){$postrealname='Name: ' . $realname . "\n";};
$email=$_POST['email'];
if(($email!='') && (ereg('@',$email))) {$postemail='Email: ' . $email . "\n";};
$message = stripslashes($message);

$to=$_POST['to'];
if($to=='pastor'){
$to='pastor's email address';
}
elseif($to=='associate'){
$to='associate minister's email address';
}
elseif($to=='youth'){
$to='youth minister's email address';
}
else{
$to='my email address';
}
$subject = "from parklandbaptistchurch.org";
$message=$message . "\n" . $postrealname . $postemail;

$headers = "From: " . $realname . " <" . $email . ">\r\n";

mail($to, $subject, $message, $headers);
echo '<p>Your message has been sent.</p>';
}
}
else { ?>

<h2>Contact Us</h2>

<p><strong>Parkland Baptist Church</strong><br />
7206 Shepherdsville Rd., Louisville, Kentucky 40219, United States<br />
Phone: 502-969-1387<br />
Fax: 502-969-1388</p>

<form action="contact.html?action=send" method="post">
<fieldset>
<legend>E-mail form</legend>
<label for="name">Name:</label><input type="text" id="name" name="realname" value="Name" onfocus="clearDefault(this)" onblur="insertDefault(this)" class="form" />
<label for="email">Email:</label><input type="text" id="email" name="email" value="Email Address" onfocus="clearDefault(this)" onblur="insertDefault(this)" class="form" />
<label for="to">Who would you like to contact?</label><select><option value="pastor">Pastor Tom Curry</option><option value="associate">Associate Minister Todd Beasley</option><option value="youth">Youth Minister Beth Turpin</option><option value="web">Web Developer Chris Huff</option></select>
<label for="message">Message:</label><textarea id="message" name="message" rows="3" cols="25" onfocus="clearDefault(this)" onblur="insertDefault(this)" class="form">Message</textarea>
<p><em>* All fields are required</em></p>
<input type="submit" value="send" class="submit" /> <input type="reset" class="submit" value="clear" />
</fieldset>
</form>

<?php } ?>

Here's my phpinfo (http://www.parklandbaptistchurch.org/phpinfo.php) if that's helpful. I noticed that I doesn't have a MAIL or _ENV["MAIL"] variable like other domains that I have. Is this the problem? If so, how do I add it?

mlseim
02-02-2007, 04:27 PM
Is your server set-up so that .html file extensions are
processed as PHP scripts? If not, rename the extension
to .php and change your <form> line.

TheShaner
02-02-2007, 05:02 PM
You must also make sure that the smtp server is set up on your web server so that you can actually send mail.

-Shane

BroChris
02-02-2007, 06:22 PM
Yes, html files are parsed for php.

And yes, it appears that smtp is set up. Any other ideas?

CFMaBiSmAd
02-02-2007, 06:33 PM
I get a fatel parse error when testing the code (looking for typo's, syntax errors...) This line is not valid code -

else($to=='web'){

BroChris
02-02-2007, 06:56 PM
Sorry, when I was editing out email addresses I wrote an error into the code. It's fixed now.

I've verified that this does work on my own local server, but it won't work once I upload it to the web server. What variables on that side of things might be causing this not to work?

CFMaBiSmAd
02-02-2007, 07:07 PM
Check your server error log and/or put the following after your first opening <?php tag -

ini_set ("display_errors", "1");
error_reporting(E_ALL);This will tell you if the mail(...) function call is failing. Also, it would not hurt to put if(mail(...)){ succeeded.. } else { failed... } conditional logic around the mail(...) function call.

BroChris
02-02-2007, 08:16 PM
Thank you so much. It's working now. Turning on errors helped me find the problem (I should have done that in the beginning...).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum