PRodgers4284 Posted March 6, 2008 Share Posted March 6, 2008 Im trying to send an email from a contact form, but im not sure if im doing this correctly, I have the contact form displaying the error messages if the user enters in the wrong data, but i cant same to get the mail to send. I have the email settings correctly set to send mail ok. Can anyone please help? The code im using to send to the mail is <?php $error_stat = 0; $name_message = ''; $email_message = ''; if (isset($_POST['submit'])) { $name = $_POST['name']; $email = $_POST['email']; //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*'; } //Name check) if (empty($enquiry)) { //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 enquiry $enquiry_message = '*Please enter your Enquiry*'; } //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>$name</b>,Enquiry 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 = ('********@googlemail.com'); $mail->AddAddress('$email'); $mail->Subject = '****Enquiry'; $mail->Body = "Enquiry Email:\n\nname: $name\nemail: $email\nemail: $enquiry\nenquiry:\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) { ?> Link to comment https://forums.phpfreaks.com/topic/94738-php-email-help/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.