Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jan 2008
    Posts
    216
    Thanks
    10
    Thanked 1 Time in 1 Post

    PHP mail problem

    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 Code:
    <?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) { 


    ?>
    Last edited by PRodgers4284; 03-06-2008 at 07:29 PM.

  • #2
    Regular Coder
    Join Date
    Jan 2008
    Posts
    216
    Thanks
    10
    Thanked 1 Time in 1 Post
    I got this working

  • #3
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    What was the solution? Helps if others have a similar problem.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #4
    Regular Coder
    Join Date
    Jan 2008
    Posts
    216
    Thanks
    10
    Thanked 1 Time in 1 Post
    Quote Originally Posted by _Aerospace_Eng_ View Post
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •