Jump to content

PHP Email help


PRodgers4284

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.