I'm using normal php mail() function to send emails. This works fine on localhost.
But in the online when i try to send a mail with images in the body with <img ../> tag the email won't go. Actually the mail function return true. Even though my inbox won't get any.
WHen I remove the <img> tags and try , emails are receiving to the inbox.
Please help
Thank you
$this->checkAuth();
//headers
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html; charset=iso-8859-1" . "\r\n";
$headers .= 'From: ' . $from . ' <' . $from . '>' . "\r\n";
$headers .= 'Reply-To: ' . $from . ' ' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($to, $subject, $message, $headers);
$this->_exit();
would be helpful if we could see your code but I'm gonna go out on a limb here and ask you to check your spam folder and make sure the image tags are formatted corectlly and that the email script contains no errors.
also here's a helpful link http://css-tricks.com/sending-nice-html-email-with-php/
Are you only sending a html mail?
Some mail scanners do not allow html only mail and need a plain text mail too, perhaps because you are sending an image it gets reported as spam.
This can block your mail from being send and as far as php is concerned it has been send.
Take a look at: http://kevinjmcmahon.net/articles/22/html-and-plain-text-multipart-email-/
Or the code:
//specify the email address you are sending to, and the email subject
$email = 'email#example.com';
$subject = 'Email Subject';
//create a boundary for the email. This
$boundary = uniqid('np');
//headers - specify your from email address and name here
//and specify the boundary for the email
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From: Your Name \r\n";
$headers .= "To: ".$email."\r\n";
$headers .= "Content-Type: multipart/alternative;boundary=" . $boundary . "\r\n";
//here is the content body
$message = "This is a MIME encoded message.";
$message .= "\r\n\r\n--" . $boundary . "\r\n";
$message .= "Content-type: text/plain;charset=utf-8\r\n\r\n";
//Plain text body
$message .= "Hello,\nThis is a text email, the text/plain version.
\n\nRegards,\nYour Name";
$message .= "\r\n\r\n--" . $boundary . "\r\n";
$message .= "Content-type: text/html;charset=utf-8\r\n\r\n";
//Html body
$message .= "
Hello,
This is a text email, the html version.
Regards,
Your Name";
$message .= "\r\n\r\n--" . $boundary . "--";
//invoke the PHP mail function
mail('', $subject, $message, $headers);
This sounds like the emails you send containing the image tags are sent to your spam mailbox.
Are you using some mail provider like gmail? They mostly throw untrusted messages directly into the spam folder. With untrusted I mean accounts which are freshly registered.
It's not something new that mails sent with PHP's native mail() function cause the messages to be detected as spam. It's the way php prepares the message headers.
So, using a php mail library like SwiftMailer is the way to go. It provides you with good customization options and contains functionality that'll make sending mails with attachments a lot easier.
Check it out: http://swiftmailer.org/docs/messages.html#attaching-files
Here's an example of how to use SwiftMailer for sending an email message with an image attachment:
<?php
require_once 'lib/swift_required.php';
// Create the Transport
$transport = Swift_SmtpTransport::newInstance('smtp.example.org', 25)
->setUsername('your username')
->setPassword('your password');
// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
// Create the message
$message = Swift_Message::newInstance()
// Give the message a subject
->setSubject('Your subject')
// Set the From address with an associative array
->setFrom(array('john#doe.com' => 'John Doe'))
// Set the To addresses with an associative array
->setTo(array('receiver#domain.org', 'other#domain.org' => 'A name'))
// Give it a body
->setBody('Here is the message itself')
// And optionally an alternative body
->addPart('<q>Here is the message itself</q>', 'text/html');
// Add the attachment
$message->attach(Swift_Attachment::fromPath('/path/to/image.jpg'));
// Send the message
$result = $mailer->send($message);
Give it a try.
Related
I am trying to send mail to multiple recipient without them seeing each others email address
this is what I have done so far
//my variable $mailto got all the emails from the database
$mailto = preg_replace('#\s+#',',',trim($mailto));
$headers = 'FROM: COMPANY INC <support#admin.com>\r\n';
$headers .= 'BBC'.$mailto."\r\n";
$headers .= 'Content-Type:text/html; charset=ISO- 8859-1\r\n';
mail($mailto, "MY TITle", $mailbody, $headers);
You are setting the wrong header. There is no BBC, and you're missing a colon.
try
$headers .= 'BCC: '.$ml."\r\n";
I am trying to generate an email on signing up to website, I am using PHP to create and send the email. My domain has both SPF and DKIM running on it. However when i spam check my email i get this:
[SPF] srv61.hosting24.com does not allow your server 31.220.105.111 to use face159#srv61.hosting24.com
[Sender ID] srv61.hosting24.com does not allow your server 31.220.105.111 to use face159#srv61.hosting24.com
Your message is not signed with DKIM
I have contacted my hosting and they confirm that all the authentication systems are working on there end, so i must be doing something wrong in the PHP code but for the life of me i can't find what here is how i generate the email:
//Emails link to voucher
//create a boundary for the email. This
$boundary = uniqid('np');
$subject = "The Forum - Little Thank You";
//headers - specify your from email address and name here
//and specify the boundary for the email
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From: TheForum#freewifisystems.co.uk" . "\r\n";
$headers .= "To: " . $email . "\r\n";
$headers .= "Content-Type: multipart/alternative;boundary=" . $boundary . "\r\n";
//here is the content body
$message = "This is a MIME encoded message.";
$message .= "\r\n\r\n--" . $boundary . "\r\n";
$message .= "Content-type: text/plain;charset=utf-8\r\n\r\n";
//Plain Email
$content2 = "plain text email here";
//Plain text body
$message .= "Hello,\nThis is a text email as HMTL is dissable, Please enable HTML to continue. \n\nRegards,\nThe Forum";
$message .= "\r\n\r\n--" . $boundary . "\r\n";
$message .= "Content-type: text/html;charset=utf-8\r\n\r\n";
//Html body
$message .= $content3;
$message .= "\r\n\r\n--" . $boundary . "--";
//invoke the PHP mail function
mail($email, $subject, $message, $headers);
?>
$email and $content3 are set via SQL and are setting correctly the email forms and is well formatted.
I am tring to sent email to multiplw users in Bcc through PHP mail scriptcode is as follows -
$recipients =array('recpient1#gmail.com','recpient2go#gmail.com');
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$to = '';
$subject = "E-mail subject";
$body = "E-mail body";
$headers = 'From: info#mydomain.com' . "\r\n" ;
$headers .= 'Reply-To: info#mydomain.com' . "\r\n";
$headers .= 'BCC: ' . implode(', ', $recipients) . "\r\n";
$email =mail($to, $subject, $body, $headers);
if we leave $to black then user in gmail detail shows "to undisclosed recipients" and Bcc not shows how can be show "Bcc me (user who got mail)" i search a lot, but didn't got any proper answer
BCC stands for Blind Carbon Copy and its main purpose is, that you can not see the other recipients of that mail.
If you want to show all email addresses use CC (Carbon Copy) instead.
Be aware, though, that all recipients now can see all other recipients' email addresses, which increases the probabilities having those email addresses end up in spam catalogs.
You can't control how the people at Gmail decide to display the recipients list when reading an email. Each webmail system decides how they want to display the recipients list.
Maybe you can fin another webmail system that decided to display "Sent to me#my-email" instead of "Undisclosed recipients"...but why does it matter to you?
Why do you care about that? I'd say it is a false problem. Since you received the email, it was of course sent to you.
i am using this code :
$to = "someone#example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse#example.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
it sends email to my gmail's SPAM folder .
Suggest any solution .
i dont want to use any PEAR MAIL type way to send email or dont want to require and include any file.
This functions works without including/requiring any additional php file.
You should use proper header like this from PHP manual
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: Mary <mary#example.com>, Kelly <kelly#example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday#example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive#example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck#example.com' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
The Gmail spam filter has lots of parts to it which determine the spamminess of mail. You could start by seeing the SPF record for your domain. Avoid using sales language, HTML and colours where possible in your email.
There's also an old but fun video from Google about how their spam filtering works.
It's all in the headers. I don't know how GMail works internally, but I've found on my projects that setting Reply-To can Content-Type headers seems to fix this.
See PHP mail() docs for an example of doing this.
(Note: I've got a PHP questionnaire/response system that sets these headers and the e-mails come through correctly to GMail, Hotmail and Yahoo! Mail).
i want know
how i can send one mail to 200 user
and i want when the email sendt
it appeare send to:user#mail.com
from:my mail
because i think i see many email like that
to:email1#exaple.com;email2#exaple.com;emial3#exaple.com;
ithink this from bbc
i mean i want every user see sent to this email only
You can use the native mail() function, separate the addresses with a comma, and put them all in the blind carbon copy list with additional headers.
$to = "jon#abc.com,sal#example.com";
$subject = "Mini-mass Emailer";
$message = "Hello World";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Your Name <me#mydomain.com>' . "\r\n";
$headers .= 'Bcc: {$to}' . "\r\n";
mail($to, $subject, $message, $headers);
Or you could iterate over the collection of email addresses and send each message individually:
$emails = array("foo#bar.com","fizz#buzz.com");
foreach ($emails as $email) {
$to = $email;
$subject = "My Subject";
$message = "Hello World";
mail($to, $subject, $message);
}
Send each mail separately to each user. You can write a helper utility function to do this iteratively.
if use mail function
use bcc in header
like this :
$headers .= 'Bcc: 1#example.com,2#example.com.............' . "\r\n";
u can use a class like phpmailer
and use AddBCC() function