We help IT Professionals succeed at work.

Sending Mail From Web Server via Google Apps

Medium Priority
397 Views
Last Modified: 2012-05-11
We use Google Apps for email and our new website contains forms. For some reason we can't send messages processed by the form using our domain name (so the messages arrives from an email address using our domain name). I have a feeling I need to authorise sending emails using the web server with Google Apps. I'm not sure how to do this, I'm thinking I need to add an SRV record which contains the IP address of our web server?
Comment
Watch Question

singh677Linux Administrator
CERTIFIED EXPERT

Commented:
Hello,

You can send mail through your domain name using below mail script.

<?php
require_once "Mail.php";

        $from = "test <user@domain.com>";
        $to = "singh <user@domain.com>";
        $subject = "Hi!";
        $body = "Hi,\n\nHow are you?";

        $host = "ssl://smtp.gmail.com";
        $port = "465";
      $username = "user@domain.com";
        $password = "w4o8Y8KOuv1";

        $headers = array ('From' => $from,
          'To' => $to,
          'Subject' => $subject);
        $smtp = Mail::factory('smtp',
          array ('host' => $host,
            'port' => $port,
            'auth' => true,
            'username' => $username,
            'password' => $password));

        $mail = $smtp->send($to, $headers, $body);

        if (PEAR::isError($mail)) {
          echo("<p>" . $mail->getMessage() . "</p>");
         } else {
          echo("<p>Message successfully sent!</p>");
         }

    ?>

Note :: Make sure the port 465 must be open your networks/firewall.

Author

Commented:
Thanks Singh677, But do I need a SRV record in the domain name or Google won't authorise sending the messages via their SMTP. That's the issue I think?
Allen FalconCEO & Pragmatic Evangelist

Commented:
Are the forms from the web site sending emails to addresses in your domain or external?  

Also, did you look at using Google Forms?
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
We used a different plug-in for Wordpress in the end. Thanks!
Jason C. LevineDon't talk to me.
CERTIFIED EXPERT

Commented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.