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/):
- smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
- biff = no
- append_dot_mydomain = no
-
- readme_directory = no
-
- mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
- mailbox_size_limit = 0
- recipient_delimiter = +
- inet_interfaces = loopback-only
- inet_protocols = all
-
- # TLS parameters
- smtp_tls_policy_maps = hash:/etc/postfix/tls_policy
- smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
- smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
- smtpd_use_tls=yes
- smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
- smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
- smtp_header_checks = pcre:/etc/postfix/smtp_header_checks
-
- myhostname = xxxxxxxxx
- alias_maps = hash:/etc/aliases
- alias_database = hash:/etc/aliases
- mydestination = xxxxxxxxxx, localhost.com, localhost
- relayhost = smtp.zoho.com:587
- smtp_sasl_auth_enable = yes
- smtp_sasl_password_maps = hash:/etc/postfix/password
- #smtp_sasl_security_options =
- smtp_generic_maps = hash:/etc/postfix/generic
- smtp_sasl_security_options = noanonymous
- smtp_always_send_ehlo = yes
- smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination
- 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:
- Jul 4 21:46:42 xxxxxxxxxx postfix/qmgr[9100]: D9B2E5E0292: from=<www-data@xxxxxxxxxx>, size=549, nrcpt=1 (queue active)
- 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)
- <?php
- $owner_email = $_POST["owner_email"];
- $headers = 'From:' . $_POST["email"];
- $subject = 'A message from your site visitor ' . $_POST["name"];
- $messageBody = "";
-
- if($_POST['name']!='nope'){
- $messageBody .= '<p>Visitor: ' . $_POST["name"] . '</p>' . "\n";
- $messageBody .= '<br>' . "\n";
- }
- if($_POST['email']!='nope'){
- $messageBody .= '<p>Email Address: ' . $_POST['email'] . '</p>' . "\n";
- $messageBody .= '<br>' . "\n";
- }else{
- $headers = '';
- }
- if($_POST['state']!='nope'){
- $messageBody .= '<p>State: ' . $_POST['state'] . '</p>' . "\n";
- $messageBody .= '<br>' . "\n";
- }
- if($_POST['phone']!='nope'){
- $messageBody .= '<p>Phone Number: ' . $_POST['phone'] . '</p>' . "\n";
- $messageBody .= '<br>' . "\n";
- }
- if($_POST['fax']!='nope'){
- $messageBody .= '<p>Fax Number: ' . $_POST['fax'] . '</p>' . "\n";
- $messageBody .= '<br>' . "\n";
- }
- if($_POST['message']!='nope'){
- $messageBody .= '<p>Message: ' . $_POST['message'] . '</p>' . "\n";
- }
-
- if($_POST["stripHTML"] == 'true'){
- $messageBody = strip_tags($messageBody);
- }
-
- try{
- if(!mail($owner_email, $subject, $messageBody, $headers)){
- throw new Exception('mail failed');
- }else{
- echo 'mail sent';
- }
- }catch(Exception $e){
- echo $e->getMessage() ."\n";
- }
Thanks for any pointers,
Gery