Contact form from ubuntu to Zoho email address

Contact form from ubuntu to Zoho email address

Hi there,

I would like some support in order to get my Postfix configuration working with my Zoho email account. What I am trying to do is to send a message from my contact form in http://www.g3eo.com/#!/page_Contacts to my Zoho email account. For that I configured Postfix in my ubuntu box in this way (based on http://emanuelesantanche.com/configuring-postfix-to-relay-email-through-zoho-mail/):

  1.     smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
  2.     biff = no
  3.     append_dot_mydomain = no
  4.    
  5.     readme_directory = no
  6.    
  7.     mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
  8.     mailbox_size_limit = 0
  9.     recipient_delimiter = +
  10.     inet_interfaces = loopback-only
  11.     inet_protocols = all
  12.    
  13.     # TLS parameters
  14.     smtp_tls_policy_maps = hash:/etc/postfix/tls_policy
  15.     smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
  16.     smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
  17.     smtpd_use_tls=yes
  18.     smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
  19.     smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
  20.     smtp_header_checks = pcre:/etc/postfix/smtp_header_checks
  21.     
  22.     myhostname = xxxxxxxxx
  23.     alias_maps = hash:/etc/aliases
  24.     alias_database = hash:/etc/aliases
  25.     mydestination = xxxxxxxxxx, localhost.com, localhost
  26.     relayhost = smtp.zoho.com:587
  27.     smtp_sasl_auth_enable = yes
  28.     smtp_sasl_password_maps = hash:/etc/postfix/password
  29.     #smtp_sasl_security_options =
  30.     smtp_generic_maps = hash:/etc/postfix/generic
  31.     smtp_sasl_security_options = noanonymous
  32.     smtp_always_send_ehlo = yes
  33.     smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination
  34.     smtpd_relay_restrictions = permit_mynetworks,permit_sasl_authenticated,defer_unauth_destination

In my website contact form things seem to be working fine, you can test it by sending a message with the Firebug open (press F12) in the Network tab. After sending the email it appears this message "mail sent" in the response tab. However, that message does not reach my email address in my Zoho email account. After checking the `/var/log/mail.log` it shows:

  1.     Jul 4 21:46:42 xxxxxxxxxx postfix/qmgr[9100]: D9B2E5E0292: from=<www-data@xxxxxxxxxx>, size=549, nrcpt=1 (queue active)
  2.     Jul 4 21:46:45 xxxxxxxxxx postfix/smtp[27824]: D9B2E5E0292: to=<info@g3eo.com>, relay=smtp.zoho.com[165.254.168.48]:587, delay=114224, delays=114222/0.01/2.6/0, dsn=4.0.0, status=deferred (SASL authentication failed; server smtp.zoho.com[165.254.168.48] said: 535 Authentication Failed)

I understand that the authentication problem is because my message could get into the Zoho smtp server, so it was rejected, not sure if it is the case. I would appreciate if someone could help to understand what is going on here and how to fix it.

My contact form uses the following files:
- http://www.g3eo.com/extras/js/forms.js

and http://www.g3eo.com/extras/bin/MailHandler.php (see below)

  1.     <?php
  2.         $owner_email = $_POST["owner_email"];
  3.         $headers = 'From:' . $_POST["email"];
  4.         $subject = 'A message from your site visitor ' . $_POST["name"];
  5.         $messageBody = "";
  6.        
  7.         if($_POST['name']!='nope'){
  8.             $messageBody .= '<p>Visitor: ' . $_POST["name"] . '</p>' . "\n";
  9.             $messageBody .= '<br>' . "\n";
  10.         }
  11.         if($_POST['email']!='nope'){
  12.             $messageBody .= '<p>Email Address: ' . $_POST['email'] . '</p>' . "\n";
  13.             $messageBody .= '<br>' . "\n";
  14.         }else{
  15.             $headers = '';
  16.         }
  17.         if($_POST['state']!='nope'){       
  18.             $messageBody .= '<p>State: ' . $_POST['state'] . '</p>' . "\n";
  19.             $messageBody .= '<br>' . "\n";
  20.         }
  21.         if($_POST['phone']!='nope'){       
  22.             $messageBody .= '<p>Phone Number: ' . $_POST['phone'] . '</p>' . "\n";
  23.             $messageBody .= '<br>' . "\n";
  24.         }   
  25.         if($_POST['fax']!='nope'){       
  26.             $messageBody .= '<p>Fax Number: ' . $_POST['fax'] . '</p>' . "\n";
  27.             $messageBody .= '<br>' . "\n";
  28.         }
  29.         if($_POST['message']!='nope'){
  30.             $messageBody .= '<p>Message: ' . $_POST['message'] . '</p>' . "\n";
  31.         }
  32.        
  33.         if($_POST["stripHTML"] == 'true'){
  34.             $messageBody = strip_tags($messageBody);
  35.         }
  36.        
  37.         try{
  38.             if(!mail($owner_email, $subject, $messageBody, $headers)){
  39.                 throw new Exception('mail failed');
  40.             }else{
  41.                 echo 'mail sent';
  42.             }
  43.         }catch(Exception $e){
  44.             echo $e->getMessage() ."\n";
  45.         }
Thanks for any pointers,

Gery