php sending mail but gmail not receiving.

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

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

#16 Bobby_Bubbles   User is offline

  • D.I.C Regular

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

Re: php sending mail but gmail not receiving.

Posted 02 June 2020 - 08:06 AM

update

$site = 'mysite.ca';
$sitename = 'mysite';
$subject = $sitename.' Promo Code';
$message = 'hiiiiii';
$headers   = [
    'MIME-Version' => 'MIME-Version: 1.0\r\n',
    'Content-type' => 'Content-Type: multipart/alternative; boundary=c4d5d00c4725d9ed0b3c8b

--c4d5d00c4725d9ed0b3c8b
Content-Type: text/plain; charset="iso-8859-1" 
Content-Transfer-Encoding: 7bit

part1

--c4d5d00c4725d9ed0b3c8b
Content-Type: text/html; charset="iso-8859-1" 
Content-Transfer-Encoding: 7bit

<b>part2</b>

--c4d5d00c4725d9ed0b3c8b--',
    'From' => ''.$sitename.' <{[email protected]'.$site.'}>\r\n',
    'Reply-To' => '[email protected]'.$site.'\r\n',
    'X-Mailer' => 'PHP/' . phpversion().'\r\n',
	'DKIM-Signature' => 'v=1; a=rsa-sha1; c=relaxed/relaxed; s=Public.key; d='.$site.';
 h=From:Date:Subject:MIME-Version:Content-Type:To:Message-ID; [email protected]'.$site.';
 bh=nTZ5dMJsUUR3AQtCHx/sfVzBrXM=;
 b=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAr3LQDd86qD6botl6oyKo
G175Kb2d1KNfQMkeI09KqmGiXs2We3td+Q526ECluzsR5vznjAWbrYh+pXSgXAeO
3xpXK7t4aAgvMBzrFWw+mtL783ULRVVnMApm65mLvGslwI10yXeJAjEOAnrgdxoP
11EHhQ4eSqJr+sf7JEnecSMtT/PdgGaHCaE3fDCvMAtNNb8/B3jx7nRy+qJFjBk6
DlrGTjbHwYlzNUjUQXWErKkXxrh6tg5TuQ0MAxgye1dW1gJVxQ6oueQqYqxckQUS
Jix8/oScE9M8NrltcGUWWqJxDP4gRFDnm/xtuUnh992zD1q1JgSVoCM+G2F8PSiX
nQIDAQAB',
];
mail('[email protected]',$subject,$message,$headers);



current code.

hers are the errors.

Warning: mail(): Header field value (Content-type => Content-Type: multipart/alternative; boundary=c4d5d00c4725d9ed0b3c8b --c4d5d00c4725d9ed0b3c8b Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit part1 --c4d5d00c4725d9ed0b3c8b Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: 7bit <b>part2</b> --c4d5d00c4725d9ed0b3c8b--) contains invalid chars or format in /home/mysite/mpadmin.php on line 41

Warning: mail(): Header field value (DKIM-Signature => v=1; a=rsa-sha1; c=relaxed/relaxed; s=Public.key; d=mysite.ca; h=From:Date:Subject:MIME-Version:Content-Type:To:Message-ID; [email protected]; bh=nTZ5dMJsUUR3AQtCHx/sfVzBrXM=; b=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAr3LQDd86qD6botl6oyKo G175Kb2d1KNfQMkeI09KqmGiXs2We3td+Q526ECluzsR5vznjAWbrYh+pXSgXAeO 3xpXK7t4aAgvMBzrFWw+mtL783ULRVVnMApm65mLvGslwI10yXeJAjEOAnrgdxoP 11EHhQ4eSqJr+sf7JEnecSMtT/PdgGaHCaE3fDCvMAtNNb8/B3jx7nRy+qJFjBk6 DlrGTjbHwYlzNUjUQXWErKkXxrh6tg5TuQ0MAxgye1dW1gJVxQ6oueQqYqxckQUS Jix8/oScE9M8NrltcGUWWqJxDP4gRFDnm/xtuUnh992zD1q1JgSVoCM+G2F8PSiX nQIDAQAB) contains invalid chars or format in /home/mysite/mpadmin.php on line 41


Was This Post Helpful? 0
  • +
  • -

#17 astonecipher   User is offline

  • Enterprise Software Architect
  • member icon

Reputation: 3150
  • View blog
  • Posts: 11,954
  • Joined: 03-December 12

Re: php sending mail but gmail not receiving.

Posted 02 June 2020 - 09:22 AM

You don't see the duplication here?
$headers   = [
    'MIME-Version' => 'MIME-Version: 1.0\r\n',
    'Content-type' => 'Content-Type: multipart/alternative; boundary=c4d5d00c4725d9ed0b3c8b


Was This Post Helpful? 0
  • +
  • -

#18 Bobby_Bubbles   User is offline

  • D.I.C Regular

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

Re: php sending mail but gmail not receiving.

Posted 02 June 2020 - 09:37 AM

i missed that but got the same issue. there is invalid characters and i dont know what its getting hung up on.

$site = 'mysite.ca';
$sitename = 'mysite';
$subject = $sitename.' Promo Code';
$message = 'hiiiiii';
$headers   = [
	'From' => ''.$sitename.' <{[email protected]'.$site.'}>\r\n',
    'Reply-To' => '[email protected]'.$site.'\r\n',
    'X-Mailer' => 'PHP/' . phpversion().'\r\n',
    'MIME-Version' => '1.0\r\n',
    'Content-type' => 'multipart/alternative; boundary=c4d5d00c4725d9ed0b3c8b

--c4d5d00c4725d9ed0b3c8b
Content-Type: text/plain; charset="iso-8859-1" 
Content-Transfer-Encoding: 7bit

part1

--c4d5d00c4725d9ed0b3c8b
Content-Type: text/html; charset="iso-8859-1" 
Content-Transfer-Encoding: 7bit

<b>part2</b>

--c4d5d00c4725d9ed0b3c8b--',
	'DKIM-Signature' => 'v=1; a=rsa-sha1; c=relaxed/relaxed; s=Public.key; d='.$site.';
 h=From:Date:Subject:MIME-Version:Content-Type:To:Message-ID; [email protected]'.$site.';
 bh=nTZ5dMJsUUR3AQtCHx/sfVzBrXM=;
 b=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAr3LQDd86qD6botl6oyKo
G175Kb2d1KNfQMkeI09KqmGiXs2We3td+Q526ECluzsR5vznjAWbrYh+pXSgXAeO
3xpXK7t4aAgvMBzrFWw+mtL783ULRVVnMApm65mLvGslwI10yXeJAjEOAnrgdxoP
11EHhQ4eSqJr+sf7JEnecSMtT/PdgGaHCaE3fDCvMAtNNb8/B3jx7nRy+qJFjBk6
DlrGTjbHwYlzNUjUQXWErKkXxrh6tg5TuQ0MAxgye1dW1gJVxQ6oueQqYqxckQUS
Jix8/oScE9M8NrltcGUWWqJxDP4gRFDnm/xtuUnh992zD1q1JgSVoCM+G2F8PSiX
nQIDAQAB',
];
mail('[email protected]',$subject,$message,$headers);


This post has been edited by Bobby_Bubbles: 02 June 2020 - 09:48 AM

Was This Post Helpful? 0
  • +
  • -

#19 astonecipher   User is offline

  • Enterprise Software Architect
  • member icon

Reputation: 3150
  • View blog
  • Posts: 11,954
  • Joined: 03-December 12

Re: php sending mail but gmail not receiving.

Posted 02 June 2020 - 09:40 AM

Try these headers,
        $headers = "From: [email protected]\r\n";
        $headers .= "Reply-To: [email protected]\r\n";
        $headers .= "MIME-Version: 1.0\r\n";
        $headers .= "Content-type: text/html; charset=utf-8\r\n";

Was This Post Helpful? 0
  • +
  • -

#20 Bobby_Bubbles   User is offline

  • D.I.C Regular

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

Re: php sending mail but gmail not receiving.

Posted 02 June 2020 - 10:58 AM

results from mail tester.

mail-tester.com/test-7bkg0zjrv&reloaded=3

says im missing the unsubscribe. but that one sent.

so whats wrong with the DKIM string?

also i thought i set up my dns records correctly...

also the website that shows up in that result is not the one im working on but is on the same host.

This post has been edited by Bobby_Bubbles: 02 June 2020 - 11:02 AM

Was This Post Helpful? 0
  • +
  • -

#21 ArtificialSoldier   User is online

  • D.I.C Lover
  • member icon

Reputation: 2757
  • View blog
  • Posts: 8,059
  • Joined: 15-January 14

Re: php sending mail but gmail not receiving.

Posted 02 June 2020 - 11:24 AM

The major problem was trying to jam everything into a content-type header. In post 18, everything from line 10 to line 24 you're saying is a single content-type header. It's not, that's what it was complaining about. You're trying to stuff the different parts of a multi-part email into a single header and that's not going to work. If you want to send multi-part emails, I would recommend using PHPMailer, not the regular mail function. You can still specify whatever other headers you want, and you can add multiple parts (plain text, HTML, etc), attachments, whatever you want, and PHPMailer will construct the email correctly. Trying to do all of that with mail is a mess.
Was This Post Helpful? 0
  • +
  • -

#22 Bobby_Bubbles   User is offline

  • D.I.C Regular

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

Re: php sending mail but gmail not receiving.

Posted 02 June 2020 - 02:44 PM

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
//use PHPMailer\PHPMailer\Exception;

require 'vendor/phpmailer/src/Exception.php';
require 'vendor/phpmailer/src/PHPMailer.php';
require 'vendor/phpmailer/src/SMTP.php';

// Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);
$site = 'truebud.ca';
$sitename = 'Truebud';
try {
    //Server settings
    //$mail->isSMTP();                                            // Send using SMTP
    $mail->Host       = 'smtp.'.$site;                    // Set the SMTP server to send through
    $mail->SMTPAuth   = true;                                   // Enable SMTP authentication
    $mail->Username   = '[email protected]'.$site;                     // SMTP username
    $mail->Password   = '[pass]';                               // SMTP password
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;         // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
    $mail->Port       = 587;                                    // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above

    //Recipients
    $mail->setFrom('[email protected]'.$site,$sitename);
    $mail->addAddress('[email protected]','Bob Smith');
    $mail->addAddress('[email protected]');
    $mail->addReplyTo('[email protected]'.$site,$sitename);
    $mail->addCC('[email protected]'.$site);
    $mail->addBCC('[email protected]'.$site);

    // Attachments
    //$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
    //$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name

    // Content
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = 'Here is the subject';
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

    $mail->send();
    echo 'Message has been sent';
} catch (Exception $e) {
    echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}



the code above i was able to send. still a problem tho s i had to disable smtp. my smtp.mysite.ca i cant ping despite me having an a record and i flushed my dns records by ipconfig /flushdns

also which smtp account are they reffering to? im trying to run a smtp server from my own hosting at my business line.
Was This Post Helpful? 0
  • +
  • -

#23 ArtificialSoldier   User is online

  • D.I.C Lover
  • member icon

Reputation: 2757
  • View blog
  • Posts: 8,059
  • Joined: 15-January 14

Re: php sending mail but gmail not receiving.

Posted 02 June 2020 - 02:59 PM

The SMTP settings are the server to send the email through, so the SMTP account settings are any valid email account that is able to send or relay mail through that server.

If that works so far, then let's go from there and keep adding features or changing things until it breaks. Did you get the email in Gmail?

You can see my point with the differences with the regular mail function though. It's a whole lot easier to do this:

    // Content
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = 'Here is the subject';
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

Than it is to try to create your own multi-part message with all of the appropriate headers and body sections.

Quote

still a problem tho s i had to disable smtp.

What does that mean, what did you disable? Is the code you posted above the working code?

Your SMTP servers comes back with 3 different IPs, is that correct? You can use an external service like this to look it up to make sure it's not just your system:

http://www.kloth.net...es/nslookup.php
Was This Post Helpful? 0
  • +
  • -

#24 Bobby_Bubbles   User is offline

  • D.I.C Regular

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

Re: php sending mail but gmail not receiving.

Posted 02 June 2020 - 03:14 PM

yes the code abov is working but i had to disable isSMTP() it wouldnt send saying "Message could not be sent. Mailer Error: SMTP connect() failed."
Was This Post Helpful? 0
  • +
  • -

#25 Bobby_Bubbles   User is offline

  • D.I.C Regular

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

Re: php sending mail but gmail not receiving.

Posted 02 June 2020 - 03:31 PM

i believe so. i have smtp.site.ca proxied behind cloudflare. will cloudflare proxy interfere with mailing services?
Was This Post Helpful? 0
  • +
  • -

#26 ArtificialSoldier   User is online

  • D.I.C Lover
  • member icon

Reputation: 2757
  • View blog
  • Posts: 8,059
  • Joined: 15-January 14

Re: php sending mail but gmail not receiving.

Posted 02 June 2020 - 03:58 PM

I'm not sure. You shouldn't need to do that though, cloudflare is mostly for cloud caching stuff, you shouldn't want to do that for a mail server. You need to connect directly to the mail server.
Was This Post Helpful? 0
  • +
  • -

#27 Bobby_Bubbles   User is offline

  • D.I.C Regular

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

Re: php sending mail but gmail not receiving.

Posted 02 June 2020 - 04:18 PM

figured. but rvealing my true ip just like that eh.......would b good to get behind a proxy but that will come later.

i disabled it for now. so when you do a ns lookup you will see the real ip.

also still doesnt work. same error.
Was This Post Helpful? 0
  • +
  • -

#28 ArtificialSoldier   User is online

  • D.I.C Lover
  • member icon

Reputation: 2757
  • View blog
  • Posts: 8,059
  • Joined: 15-January 14

Re: php sending mail but gmail not receiving.

Posted 02 June 2020 - 04:35 PM

That might be a caching issue, DNS records that get cached for a while (we have ours set to 2 days), they can get cached in multiple places, and they can be unpredictable to clear. If you want eliminate DNS caching as a reason, use the IP address instead of the host name in your code.
Was This Post Helpful? 0
  • +
  • -

#29 Bobby_Bubbles   User is offline

  • D.I.C Regular

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

Re: php sending mail but gmail not receiving.

Posted 02 June 2020 - 06:20 PM

the ip address bypasses the cache?

i trid the ip address but nothing.

where exactly would these accounts be stored to verify my smtp sttings.

sorry my "e" likes to not work half the time.

This post has been edited by Bobby_Bubbles: 02 June 2020 - 06:23 PM

Was This Post Helpful? 0
  • +
  • -

#30 ArtificialSoldier   User is online

  • D.I.C Lover
  • member icon

Reputation: 2757
  • View blog
  • Posts: 8,059
  • Joined: 15-January 14

Re: php sending mail but gmail not receiving.

Posted 02 June 2020 - 07:53 PM

DNS is just a lookup from a host name to an IP, so if you use the IP you're not using DNS.

Your SMTP settings are any email account with permission to send or relay mail, so they're configured on the mail server.
Was This Post Helpful? 0
  • +
  • -

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