php sending mail but gmail not receiving.

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • Last »

45 Replies - 1810 Views - Last Post: 14 July 2020 - 03:11 AM Rate Topic: -----

#1 Bobby_Bubbles   User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 393
  • Joined: 13-March 18

php sending mail but gmail not receiving.

Posted 31 May 2020 - 05:33 AM

$to = '[email protected]';
		$count = 0;
		$limit = 1;
		while($count < $limit){
			$count++;
			mail($to,$_POST['subject'],$_POST['message'],"From: example.com <[email protected]>");
			echo 'Done - '.$count.'<br/>';
		}



when i run this on my business net line it sends to my hotmail fine but gmail i never get it.

This post has been edited by Bobby_Bubbles: 31 May 2020 - 05:35 AM


Is This A Good Question/Topic? 0
  • +

Replies To: php sending mail but gmail not receiving.

#2 astonecipher   User is offline

  • Enterprise Software Architect
  • member icon

Reputation: 3151
  • View blog
  • Posts: 11,956
  • Joined: 03-December 12

Re: php sending mail but gmail not receiving.

Posted 31 May 2020 - 06:41 AM

Missing headers make email sent this way get caught be spam filters more frequently. It also, is extremely unreliable to begin with.
Was This Post Helpful? 0
  • +
  • -

#3 Bobby_Bubbles   User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 393
  • Joined: 13-March 18

Re: php sending mail but gmail not receiving.

Posted 31 May 2020 - 02:32 PM

i expanded but still not getting through.


$to = '[email protected]';
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';

// Additional headers
$headers[] = 'To: Bob <'.$to.'>';
$headers[] = 'From: bernie <[email protected]>';
$headers[] = 'Cc: [email protected]';
$headers[] = 'Bcc: [email protected]';
mail($to,'no subject','tst',$headers);



which headers am i missing?
Was This Post Helpful? 0
  • +
  • -

#4 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2760
  • View blog
  • Posts: 8,066
  • Joined: 15-January 14

Re: php sending mail but gmail not receiving.

Posted 31 May 2020 - 05:02 PM

Are you sending mail from the correct server? If you're saying the mail is from bernie.ca, is the server where you're actually sending from the web server for bernie.ca?
Was This Post Helpful? 0
  • +
  • -

#5 Bobby_Bubbles   User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 393
  • Joined: 13-March 18

Re: php sending mail but gmail not receiving.

Posted 31 May 2020 - 05:19 PM

yes. i have the dns pointing to my server. and the script is executed under the same domain.
Was This Post Helpful? 0
  • +
  • -

#6 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2760
  • View blog
  • Posts: 8,066
  • Joined: 15-January 14

Re: php sending mail but gmail not receiving.

Posted 31 May 2020 - 05:51 PM

I don't know what GMail specifically expects, but things like SPF and DKIM will help.
Was This Post Helpful? 0
  • +
  • -

#7 astonecipher   User is offline

  • Enterprise Software Architect
  • member icon

Reputation: 3151
  • View blog
  • Posts: 11,956
  • Joined: 03-December 12

Re: php sending mail but gmail not receiving.

Posted 31 May 2020 - 06:07 PM

Headers are missing line breaks expected, \r\n
Was This Post Helpful? 0
  • +
  • -

#8 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2760
  • View blog
  • Posts: 8,066
  • Joined: 15-January 14

Re: php sending mail but gmail not receiving.

Posted 31 May 2020 - 07:01 PM

Good call, $headers should either be a string or an array where the key names are the header names.
Was This Post Helpful? 0
  • +
  • -

#9 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6876
  • View blog
  • Posts: 31,666
  • Joined: 10-May 07

Re: php sending mail but gmail not receiving.

Posted 31 May 2020 - 07:49 PM

It's better to test from the same domain to the same domain. Then when you know it's working, you can move onto other domains. That way, if gmail isn't working, you know it's a spam issue & the technology is working.
Was This Post Helpful? 0
  • +
  • -

#10 Bobby_Bubbles   User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 393
  • Joined: 13-March 18

Re: php sending mail but gmail not receiving.

Posted 01 June 2020 - 07:15 AM

im looking up skp and dkim right now. what other headers am i missing?

or should i rally just be using my phpmailer? problem is i could never get it to work...

I have never been able to get any smtp to work on a pi and was following this guide --> https://www.raspberr...ic.php?t=210084
Was This Post Helpful? 0
  • +
  • -

#11 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2760
  • View blog
  • Posts: 8,066
  • Joined: 15-January 14

Re: php sending mail but gmail not receiving.

Posted 01 June 2020 - 10:44 AM

I use PHPMailer, I think it's pretty good. But it's a good point to test using an address and domain that you control that isn't filtering anything out first to make sure it works before testing with something like GMail.
Was This Post Helpful? 0
  • +
  • -

#12 astonecipher   User is offline

  • Enterprise Software Architect
  • member icon

Reputation: 3151
  • View blog
  • Posts: 11,956
  • Joined: 03-December 12

Re: php sending mail but gmail not receiving.

Posted 01 June 2020 - 10:53 AM

I prefer service based, so things like SendGrid or MailGun are what I use.
Was This Post Helpful? 0
  • +
  • -

#13 Bobby_Bubbles   User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 393
  • Joined: 13-March 18

Re: php sending mail but gmail not receiving.

Posted 01 June 2020 - 05:48 PM

i decided to get back to roundcube mail. i got the sit there but when i login i gt connection to storage server failed.

Here is all i did.

home/webmail.mysite/

<?php
$config = array();
$config['enable_installer'] = false;
$config['db_dsnw'] = 'mysql://roundcube_db:[rcpass]@localhost/roundcube_db';
$config['default_host'] = 'imaps://mail.mysite.ca';
$config['default_port'] = '993';
$config['smtp_server'] = 'tls://Mailer-Hermes';
$config['smtp_port'] = 587;
$config['smtp_user'] = '';
$config['smtp_pass'] = '';
$config['support_url'] = '';
$config['product_name'] = Webmail';
$config['des_key'] = 'some24charkeypass';
$config['plugins'] = array(
    'archive',
    'zipdownload',
);
$config['skin'] = 'elastic';



dovecot.service - Dovecot IMAP/POP3 email server
   Loaded: loaded (/lib/systemd/system/dovecot.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2020-06-02 00:51:13 BST; 48min ago
     Docs: man:dovecot(1)
           http://wiki2.dovecot.org/
 Main PID: 2408 (dovecot)
    Tasks: 4 (limit: 4915)
   Memory: 2.7M
   CGroup: /system.slice/dovecot.service
           ├─2408 /usr/sbin/dovecot -F
           ├─2426 dovecot/anvil
           ├─2427 dovecot/log
           └─2428 dovecot/config

Jun 02 00:51:13 raspberrypi systemd[1]: Started Dovecot IMAP/POP3 email server.
Jun 02 00:51:14 raspberrypi dovecot[2408]: master: Dovecot v2.3.4.1 (f79e8e7e4) starting up for imap, pop3, lmtp (core dumps disabled)




postfix.service - Postfix Mail Transport Agent
   Loaded: loaded (/lib/systemd/system/postfix.service; enabled; vendor preset: enabled)
   Active: active (exited) since Tue 2020-06-02 00:20:14 BST; 1h 20min ago
  Process: 852 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
 Main PID: 852 (code=exited, status=0/SUCCESS)

Jun 02 00:20:14 raspberrypi systemd[1]: Starting Postfix Mail Transport Agent...
Jun 02 00:20:14 raspberrypi systemd[1]: Started Postfix Mail Transport Agent.



server {
    listen 80;
    listen [::]:80;
    server_name webmail.mysite.ca;
    location /.well-known/acme-challenge/ {
        default_type "text/plain";
        allow all;
    }
    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name webmail.mysite.ca;
    index index.php index.html index.htm;
    root /home/webmail.mysite;
    # Disable loging for
    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt { access_log off; log_not_found off; }
    # Point index to the Laravel front controller.
    index index.php index.html index.htm;
    charset utf-8;
    server_tokens off;
    sendfile off;
    fastcgi_intercept_errors on;
    client_max_body_size 10m;
    #include /etc/nginx/template/SSL.conf;
    #include /etc/nginx/template/standard.conf;
    location /.well-known/acme-challenge/ {
        default_type "text/plain";
        allow all;
    }
    ssl on;
    # Optimisation
    ssl_stapling on;
    ssl_stapling_verify on;
    # FastCgi
    fastcgi_param HTTPS on;
    fastcgi_param HTTP_SCHEME https;
    # enable session resumption to improve https performance
    ssl_session_cache shared:SSL:50m;
    ssl_session_timeout 5m;
    # Diffie-Hellman parameter for DHE ciphersuites, recommended 2048 bits
    ssl_dhparam /home/certs/dhparam.pem;
    # enables server-side protection from BEAST attacks
    ssl_prefer_server_ciphers on;
    # disable SSLv3(enabled by default since Nginx 0.8.19) since it's less secure than TLS
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    # ciphers chosen for forward secrecy and compatibility
    ssl_ciphers "ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS";
    # enable ocsp stapling (mechanism by which a site can convey certificate revocation information to visitors in a privacy-preserving, scalable manner)
    resolver 8.8.8.8 valid=360s ipv6=off; # Google DNS
    resolver_timeout 15s;
    add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload";
    # ssl certificates
    ssl_certificate /etc/letsencrypt/live/webmail.mysite.ca/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/webmail.mysite.ca/privkey.pem;
    location ~ ^/(README.md|INSTALL|LICENSE|CHANGELOG|UPGRADING)$ {
        deny all;
    }
    location ~ ^/(bin|SQL|config|temp|logs)/ {
        deny all;
    }
    location / {
        try_files $uri $uri/ /index.php?q=$uri&$args;
    }
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}



smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

readme_directory = no

# See http://www.postfix.org/COMPATIBILITY_README.html -- default to 2 on
# fresh installs.
compatibility_level = 2

# TLS parameters
smtpd_tls_cert_file=/etc/letsencrypt/live/mail.mysite.ca/fullchain.pem
smtpd_tls_key_file=/etc/letsencrypt/live/mail.mysite.ca/privkey.pem
smtpd_use_tls=yes
smtpd_tls_auth_only = yes


#Disable Poodle
smtp_tls_security_level = may
smtpd_tls_mandatory_protocols=!SSLv2,!SSLv3
smtp_tls_mandatory_protocols=!SSLv2,!SSLv3
smtpd_tls_protocols=!SSLv2,!SSLv3
smtp_tls_protocols=!SSLv2,!SSLv3
# Changes to SSL Ciphers
tls_preempt_cipherlist = yes
smtpd_tls_mandatory_ciphers = high
tls_high_cipherlist = ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:DHE-DSS-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA256:ADH-AES256-GCM-SHA384:ADH-AES256-SHA256:ECDH-RSA-AES256-GCM-SHA384:ECDH-ECDSA-AES256-GCM-SHA384:ECDH-RSA-AES256-SHA384:ECDH-ECDSA-AES256-SHA384:AES256-GCM-SHA384:AES256-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:DHE-DSS-AES128-GCM-SHA256:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES128-SHA256:DHE-DSS-AES128-SHA256:ADH-AES128-GCM-SHA256:ADH-AES128-SHA256:ECDH-RSA-AES128-GCM-SHA256:ECDH-ECDSA-AES128-GCM-SHA256:ECDH-RSA-AES128-SHA256:ECDH-ECDSA-AES128-SHA256:AES128-GCM-SHA256:AES128-SHA256:NULL-SHA256


smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes

smtpd_recipient_restrictions =
          permit_sasl_authenticated,
          permit_mynetworks,
          reject_unauth_destination


# Milter configuration
# OpenDKIM
milter_default_action = accept
# Postfix ≥ 2.6 milter_protocol = 6, Postfix ≤ 2.5 milter_protocol = 2
milter_protocol = 6
smtpd_milters = unix:/var/run/opendkim/opendkim.sock
non_smtpd_milters = unix:/var/run/opendkim/opendkim.sock

#smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
#smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.

#smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = Mailer-Hermes
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = $myhostname, localhost
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
#mailbox_command = procmail -a "$EXTENSION"
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
#inet_protocols = ipv4


#Handing off local delivery to Dovecot's LMTP, and telling it where to store mail
virtual_transport = lmtp:unix:private/dovecot-lmtp

#Virtual domains, users, and aliases
virtual_mailbox_domains = mysql:/etc/postfix/mysql-virtual-mailbox-domains.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-mailbox-maps.cf
virtual_alias_maps = mysql:/etc/postfix/mysql-virtual-alias-maps.cf



i deleted dovecot config files and let it rebuild it on login. no go.

i checkd the permissions it belongs to www-data

i forwarded ports 587 993 and 995

ive been trying to wrap my head around it all day since i figure roundmail will take care of that for you i figure its a solution until i can do it myself. unfortunatly i needed this solution last week.

no logs for the webmail.

what have i missed?

This post has been edited by Bobby_Bubbles: 01 June 2020 - 06:07 PM

Was This Post Helpful? 0
  • +
  • -

#14 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2760
  • View blog
  • Posts: 8,066
  • Joined: 15-January 14

Re: php sending mail but gmail not receiving.

Posted 01 June 2020 - 06:08 PM

There are several things online if you search for that error message, but this is 90 degrees away from what you were trying to do earlier.
Was This Post Helpful? 0
  • +
  • -

#15 Bobby_Bubbles   User is offline

  • D.I.C Regular

Reputation: 1
  • View blog
  • Posts: 393
  • Joined: 13-March 18

Re: php sending mail but gmail not receiving.

Posted 01 June 2020 - 06:55 PM

i know and its driving me nuts.

but for the skp and dkim front i got these entries

TXT v=DMARC1; p=none
TXT v=spf1 mx -all

not sure how to do the dkim for generating the key.

update...

so i generated a key with these

openssl genrsa -out private.key 2048
openssl rsa -in private.key -pubout -out public.key



and then here is my dns records relating to it.

default._domainkey[mysite.ca] 14400 IN TXT ("v=DKIM1; k=rsa; p=""MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAr3LQDd86qD6botl6oyKo""G175Kb2d1KNfQMkeI09KqmGiXs2We3td+Q526ECluzsR5vznjAWbrYh+pXSgXAeO""3xpXK7t4aAgvMBzrFWw+mtL783ULRVVnMApm65mLvGslwI10yXeJAjEOAnrgdxoP""11EHhQ4eSqJr+sf7JEnecSMtT/PdgGaHCaE3fDCvMAtNNb8/B3jx7nRy+qJFjBk6""DlrGTjbHwYlzNUjUQXWErKkXxrh6tg5TuQ0MAxgye1dW1gJVxQ6oueQqYqxckQUS""Jix8/oScE9M8NrltcGUWWqJxDP4gRFDnm/xtuUnh992zD1q1JgSVoCM+G2F8PSiX""nQIDAQAB")


This post has been edited by Bobby_Bubbles: 01 June 2020 - 07:47 PM

Was This Post Helpful? 0
  • +
  • -

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • Last »