Page 1 of 1

PHP email script doesnt work - help

Posted: Wed Apr 02, 2008 5:32 pm
by jwan84
I got this email script from this php book that i bought
it looks good. but dosnt send..
and i have no idea why. please help !

<?php
//set flag whether mail has sent
$mailSent = false;
if (array_key_exists('ewComments',$_POST))
{
//mail processing code
//setting variables
$to = 'webmaster@pimpinformation.com';
$subject = 'Comments From PimpInformation.com';


//message structure
$message = 'From:'.$_POST['name']. "\n\n";
$message .= 'Email:'.$_POST['email']. "\n\n";
$message .= 'Comments:'.$_POST['message'];

//validate name
$name = trim($_POST['name']);
if (empty($name)) {
$error['name'] = 'Please Enter Name';
}
$email = $_POST['email'];
//validate email
$pattern = '/^[^@]+@[^\s\r\n\'";,@%]+$/';
if (!preg_match($pattern, trim($email))) {
$error['email'] = 'Please Enter Valid Email Address';
}

//validate message
$messageBody = trim($_POST['message']);
if (empty($messageBody)) {
$error['message'] = 'Please Enter Comments in Box';
}

//build the message
$message = 'On ' .date('l, M j, Y').'at,'.date('g:ia').',';
$message .= "$name ($email) Wrote: \n\n";
$message .= $messageBody;

//send mail if no errors
if (!isset($error)) {
$mailSent = mail( $to, $subject, $message );
if (!$mailSent) {
$error['notSent'] = 'Sorry, There Was Problem Sending Your Mail
Plase Try Again Later.';
}
}
}
?>

header-------------
body--------------

<div class="item">
<h1>Contact Us</h1>
<?php if (isset($error['notSent'])) { ?>
<p>Server Error</P>
<p class="warning"><?php echo $error['notSent']; ?></p>
<?php } elseif ($mailSent) { ?>
<p>Thank You for Your Comments</P>
<p>Your Mail Has Been Sent</P>
<?php } else { ?>
<p>Send Us Your Comments</P>
<p>Article Ideas, Site Improvement or anything you want to say to Our Webmaster</P>
<?php } ?>
<p><form id="contact form" name="Contact Form" method="post" action="">
<p>
<label for="name">Name:</label>
<?php if (isset($error['name'])) { ?><span class="warning">
<?php echo $error['name']; ?></span><?php } ?>
<br />
<input type="text" name="name" id="name" <?php if (isset($error)) { echo "value='$name'"; } ?> />
</p>
<p>&nbsp;</p>
<p>
<label for="email">Email:</label>
<?php if (isset($error['email'])) { ?><span class="warning">
<?php echo $error['email']; ?></span><?php } ?>
<br />
<input type="text" name="email" id="email" <?php if (isset($error)) { echo "value='$email'"; } ?> />
</p>
<p>&nbsp;</p>
<p>
<label for="message">Comments:</label>
<?php if (isset($error['message'])) { ?><span class="warning">
<?php echo $error['message']; ?></span><?php } ?>
<br />

</p><textarea name="message" id="message" cols="60" rows="6"><?php if (isset($error)) { echo $messageBody; } ?></textarea>
<p>&nbsp;</p>
<p>
<input name="ewComments" type="submit" id="ewComments" value="Send Comments" />
</p><p>&nbsp;</p></form>
</div>

Re: PHP email script doesnt work - help

Posted: Wed Apr 02, 2008 9:58 pm
by michaelh613
Are you receiving an error when you run the page. What is the exact problem
If the problem is mail isn't going I would suggest first starting writing a simple piece of code and make sure that works with your server.


BTW to learn PHP Mail check out the docs at http://us2.php.net/mail

Re: PHP email script doesnt work - help

Posted: Thu Apr 03, 2008 1:34 pm
by jwan84
ok, so i found out i need phpmailer. i downloaded the file, but in the installation file, tells me to put the file in the directory of php.ini . problem is . i cant find php.ini anywhere.......
whats wrong w. my server?