...

View Full Version : PHP mail problem



PRodgers4284
03-06-2008, 07:27 PM
I am trying to send an email from a basic contact form, but im having difficulty gettiing it to send, i have the email working on another form, it works fine. The contact form does not send the email once i have selected the submit button. Can anyone help?

My code is:


<?php
$error_stat = 0;
$name_message = '';
$email_message = '';



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


//Error checking


//Name check)
if (empty($name)) {
//Set the error_stat to 1, which means that an error has occurred
$error_stat = 1;

//Set the message to tell the user to enter a username
$name_message = '*Please enter a username*';
}




//Email check)
if (empty($email)) {
//Set the error_stat to 1, which means that an error has occurred
$error_stat = 1;

//Set the message to tell the user to enter an email address
$email_message = '*Please enter your email address*';
}

//Check format of email address entered
else if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email)){
$error_stat = 1;
//Set the message to tell the user to enter a valid email address
$email_message = '*Invalid Email Address*';
}

$email = $_POST['email'];
$email = trim($email);

if (strlen($email) > 30){
$error_stat = 1;
$email_message = '*The email address must be 30 characters or less*';
}



//Then, only run the query if there were no errors (if $error_stat still equals 0)
if ($error_stat == 0) {

echo "<h3>Registration Successful!</h3>";
echo "<p>Thankyou, <b>$username</b>,registration was successful</p>";
echo "<p>login.</p>";
echo "<a href=\"index.php\">Login</a>";

//Send out email activation

require_once('class.phpgmailer.php');
$mail = new PHPGMailer();
$mail->IsSMTP(); // send via SMTP
$mail->Host = 'ssl://smtp.gmail.com'; // SMTP servers
$mail->FromName = (*******);
$mail->AddAddress($email);
$mail->Subject = 'Enquiry';
$mail->Body = "Enquiry from:\n\nname: $name\n\n";
$mail->Send();
}
}

//Then, for the form, only show it if 1) the form hasn't been submitted yet OR 2) there is an error
if (!isset($_POST['submit']) || $error_stat == 1) {


?>

PRodgers4284
03-06-2008, 07:55 PM
I got this working

_Aerospace_Eng_
03-06-2008, 09:11 PM
What was the solution? Helps if others have a similar problem.

PRodgers4284
03-07-2008, 01:26 PM
What was the solution? Helps if others have a similar problem.

Aerospace the problem was the $email in the add address, i hadnt set it properly in the form.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum