SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Jun 2012
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Trouble sending email using php form

    Hi I am going crazy trying to send an email using XAMPP, my php form on my localhost server.

    This is the email section of the code


    PHP Code:
    if($insert_result)
            {    
                
                
    ini_set('SMTP''ssl://smtp.gmail.com');
                
    ini_set('smtp_port'465); 
                
    ini_set('sendmail_from''myemail@gmail.com');
                
    ini_set('sendmail_path''localhost\C:\Program Files\xampp\sendmail\sendmail.exe');$to $_REQUEST['email'];
                
    $message "Please fill out a survey form. Follow this link---> <a href='{$email_link}'>HERE</a> to load the form.<br>";
                
    $nameTo "Dear User"
                
    $subject "Form completion required!";
                
    $headers "MIME-Version: 1.0" '\r\n';
                
    $headers .= "Content-type: text/html; charset=iso-8859-1" '\r\n';
                
    $headers .= "From: myemail@gmail.com" '\r\n';

                
    $sent mail($to$subject$message$headers) ; 
                if(
    $sent
                {print 
    "Your mail was sent successfully"; }
                else 
                {print 
    "We encountered an error sending your mail";
                echo 
    $message;
                
    phpinfo();
                } 
    Right now, I am trying to use gmail's SMTP server. And it gives the following error:

    Warning: mail() [function.mail]: Failed to connect to mailserver at "ssl://smtp.gmail.com" port 465, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\xampp\htdocs\survey.php on line 328

    I modified the sendmail.ini and entered my username and password in the auth_username and auth_password fields and restarted XAMPP. No result.

    Earlier I tried sending using my company's ISP server. But it says Client is not authenticated.

    I printed phpinfo() to check whats wrong. Its using the same php.ini file I am modifying and the local values of SMTP and smtp_port are changing but not the master values.

    Mercury is running in my XAMPP Control Panel. Do I need to setup mercury? I just can't figure this out. I really hope someone can help me sort this out ASAP. Much appreciated.

  2. #2
    SitePoint Zealot
    Join Date
    Apr 2003
    Posts
    181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sounds like a server problem rather than something up with your script. I'd verify that's all in order first.

  3. #3
    SitePoint Member
    Join Date
    Jun 2012
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah I thought so too. So I changed the server to my company's server and tried again. And now it says "Your mail was sent successfully" only that I haven't received any mail. What all do I need to verify? Cos I am doing this for the first time.

  4. #4
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Keep it real simple to start with and then build the complexity back in, I cannot see where $to has been set in your code:

    email_test.php
    PHP Code:

    // ini set stuff here then:

    $to "your real email here";
    $subject "test subject";
    $message "test message";

        
    $sent mail($to$subject$message) ;  
    if( 
    $sent ) {

    echo 
    "email sent to $to";

    }else{

    echo 
    "email fail";
     


  5. #5
    SitePoint Member ▀hawin Patel's Avatar
    Join Date
    Jul 2012
    Location
    Vallabh Vidyanagar, Gujarat, India, India
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Insert in to your info@domainname.com not gmail.com becay\use email privacy is changed, so insert your own domain name....

    $to = "info@yourdomain.com";
    $subject = "test subject";
    $message = "test message";

    $sent = mail($to, $subject, $message) ;
    if( $sent ) {

    echo "email sent to $to";

    }else{

    echo "email fail";

    }

    Thanks
    Bhawin
    <snip>
    Last edited by TechnoBear; Jul 3, 2012 at 03:51. Reason: Please wait 90 days for a real signature


Bookmarks

Posting Permissions

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