google smtp with php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • angelicdevil
    New Member
    • Apr 2009
    • 116

    google smtp with php

    how can we use google smtp server to send mail using php

    here's my current php script

    Code:
    <?php
    
    $toName		= "my name";
    $toEmail	= "myemail@example.org";
    $subject	= "success";
    
    $name		= $_POST["name"];
    $email		= $_POST["email"];
    
    
    
    $headers = "From: Your Name <myemail@example.org>" . "\r\n";
    $headers .= "Reply-To: Your Name <myemail@example.org>" . "\r\n";
    $headers .= "X-Mailer: PHP/" . phpversion();
    
    $message= "name: $name
    email: $email
    
    
    ";
    
    $replySubject	= "Mail from me";
    $replyMessage	= "I will reply to your query soon";
    
    
    // send email  to You //
    
    
    	mail($toName." <".$toEmail.">", $subject, $message, "From: ".$name." <".$email.">");
    // send email  to You //
    
    	print "process=complete";
    
    // send reply email to inquirer //
    	mail ($name." <".$email.">", $replySubject, $replyMessage, $headers);
    // send reply email to inquirer //
    
    ?>
  • miraan
    New Member
    • Apr 2008
    • 24

    #2
    The smtp server you use is configured on your server, for example, your Apache configuration file. I'm not sure if Google allow everyone to use their smtp server though. You might want to check.

    Comment

    • angelicdevil
      New Member
      • Apr 2009
      • 116

      #3
      isnt there a way i can send in the remote server details in the php and ask mail function to use the details provided in the script itself

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        I'm not sure if Google allow everyone to use their smtp server though.
        all you need is a google account (usually).
        and ask mail function to use the details provided in the script
        you might have read that mail() doesn’t use an SMTP server …

        Comment

        • angelicdevil
          New Member
          • Apr 2009
          • 116

          #5
          so any other way other than mail();

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            of course. there is e.g. the SwiftMailer library

            Comment

            Working...