Sendign email with PHP

SBSP

Senior Member
Joined
Sep 7, 2007
Messages
663
I’m working on a new web based project that will allow someone to upload PDFs that contain invoices. Each invoice in PDF format has a string that contains the email address where it has to be sent along with the domain where it must come from.

Say my website is called whatever.com
I imagine if I change the from: address’s domain name ‘@whatever.com’ to @newdomain.com’ it will cause spam filters to block it because it will fail a reverse lookup ? Or don’t spam filers use reverse lookups anymore ? How do systems like O365 get around this ?
 

battletoad

Expert Member
Joined
Mar 10, 2009
Messages
1,451
I've set the "From" header to very many random/made-up-on-the-spot domain names and they always seem to get through. I suppose if you use a blacklisted domain then those would be blocked.
 

_kabal_

Executive Member
Joined
Oct 24, 2005
Messages
5,922
You will find that it depends on the recipient servers

Hotmail and Gmail for instance are very strict and will reverse lookup. This of course makes sense. Otherwise anyone could sent email from anyone.

office 365 and google apps get around this because of mx records.
 

SBSP

Senior Member
Joined
Sep 7, 2007
Messages
663
I've set the "From" header to very many random/made-up-on-the-spot domain names and they always seem to get through. I suppose if you use a blacklisted domain then those would be blocked.

You will find that it depends on the recipient servers

Hotmail and Gmail for instance are very strict and will reverse lookup. This of course makes sense. Otherwise anyone could sent email from anyone.

office 365 and google apps get around this because of mx records.

Thank You.

Sounds like its not going to work out. I also don't think it will look good if it comes from the "Real" doamain and on behalf of.
 

flippakitten

Expert Member
Joined
Aug 5, 2015
Messages
2,486
Thank You.

Sounds like its not going to work out. I also don't think it will look good if it comes from the "Real" doamain and on behalf of.

All depends on your SPF, DKIM and Dmarc of the domains.

If Dmarc p is set to reject for the from domain, it's going to bounce. ie. try setting the from to a @yahoo.com email address.

What's the purpose of sending from a specific domain?

Anyway, your safest bet would be to use their domain at generic domain so if it needs to come from "mydomain.com" you do something like:
"mydomain@generic_domain.com"
 

Thor

Honorary Master
Joined
Jun 5, 2014
Messages
44,236
Use PHP mailer - it's dead simple.

PHP:
<?php
require_once "vendor/autoload.php";


$mail = new PHPMailer;

//$mail->SMTPDebug = 3;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'user@example.com';                 // SMTP username
$mail->Password = 'secret';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                    // TCP port to connect to

$mail->setFrom('from@example.com', 'Mailer');
$mail->addAddress('joe@example.net', 'Joe User');     // Add a recipient
$mail->addAddress('ellen@example.com');               // Name is optional
$mail->addReplyTo('info@example.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');

$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$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';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}
 

SBSP

Senior Member
Joined
Sep 7, 2007
Messages
663
All depends on your SPF, DKIM and Dmarc of the domains.

If Dmarc p is set to reject for the from domain, it's going to bounce. ie. try setting the from to a @yahoo.com email address.

What's the purpose of sending from a specific domain?

Anyway, your safest bet would be to use their domain at generic domain so if it needs to come from "mydomain.com" you do something like:
"mydomain@generic_domain.com"
Thanks that's an Idea!.

I created this tool using itext sharp, It allows you to distribute your company invoices to your customers, You simply run all of your invoices in one report to PDF from I.E Crystal Reports (If you know the software called Spindle, pretty much the same way) , each invoice has a string on it with values that will tell the tool where to send the invoice to, It also groups them before sending. So basically it automates the sending of invoices. initially I was just playing and turned it in to something I could sell only to find out afterwards that iText Sharp is only open source when you dont make money off it, and after reading a bit more on their history they seem to be a bit against the Open source spirit. And Very expensive! I suddenly dont feel like using their libraries with potential hidden Licensing secrets or future changes.

So now I would like to change gears and make a tool that will allow small companies automate their invoices using an online tool. This time totally free.


Just use SendGrid?
Looks like it is what I'm trying to accomplish.



Use PHP mailer - it's dead simple.

PHP:
<?php
require_once "vendor/autoload.php";


$mail = new PHPMailer;

//$mail->SMTPDebug = 3;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'user@example.com';                 // SMTP username
$mail->Password = 'secret';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                    // TCP port to connect to

$mail->setFrom('from@example.com', 'Mailer');
$mail->addAddress('joe@example.net', 'Joe User');     // Add a recipient
$mail->addAddress('ellen@example.com');               // Name is optional
$mail->addReplyTo('info@example.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');

$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$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';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}

Thanks , I do however have a preferred piece of code snippet that I like to use.
 
Last edited:
Top