Why php mail has delay when sending message with images - html

I was building a email functionality for my website and I am using PHP mail function. The issue I am having is that when I try to email a client with a image inside a message it takes forever(20-45 minutes) to get to them and when I just include text it gets to them right away. Is there solution to this. Thanks for any help.
<?php
$email = $_COOKIE["email"];
$link = $_COOKIE["coupon"];
$to = $email;
$subject = 'Your ads';
$message = ' Hello This is Testing Email 3.0 Text & Image Your Coupon Link
<img src="$link" width="300" height="300"/> ';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Ads <ads#advertising.com>' . "\r\n";
mail($email, $subject, $message, $headers);
?>

According to your code, you mail is a top tier Spam grade for almost all anti spamming mailing protection.
They will most likely put your mail in a slow queue because of that, delaying the message because it was considered an annoyance.
Your From header contains 'ads' and 'advertising' (even if I guess that advertising.com isn't your domain.
You also have little to no text, the word test in it and a big link button named "coupon".
You should try to make your email more personal.
This is the most likely problem.
Second one would be the file transfer.
If you're transferring from China to New-York with a 56kb/s connection, the file transfer will take long enough for your recipient to die from old age.
For your second problem, replace
$message = ' Hello This is Testing Email 3.0 Text & Image Your Coupon Link
<img src="$link" width="300" height="300"/> ';
by
$message = ' Hello This is Testing Email 3.0 Text & Image Your Coupon Link
<img src="' . $link . '" width="300" height="300"/> ';

Related

Random Spaces in PHP message

I am using the following PHP code to send e-mail when the users submits a form.
$to = 'mail#example.com';
$subject = 'Thank you for your mail ' . $mailRefrence . ' - www.example.com';
$headers = "From: " . 'info#example.com' . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$message = "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'> <html xmlns='http://www.w3.org/1999/xhtml'> <head> <meta http-equiv='Content-Type' content='text/html;.......";
$message .= $mailReference;
mail($to, $subject, $message, $headers);
Please note that the HTML-code inside the $message-variable is much longer, I've just removed it due to it is way to long to be pasted here. The source code is available here: http://zurb.com/playground/projects/responsive-email-templates/basic.html
However, when the mail is sent to the user, there is random spaces in the text. Sometimes the spaces appear in the text, and sometimes in the code which often ruins the whole design of the mail.
Does anyone have an idea why this happens and how to solve it?
Use trim
http://php.net/manual/en/function.trim.php
this will remove white space

Generating customized HTML text with fields/placeholders at several places in body

I am trying to send out 100 emails with HTML text body as follows :
Hello XYZ, I went to your Company X in PlaceY yesterday and was
impressed. I want to propose to you ProductZ. XYZ would be benefited by Productz
Subheading in Bold Are you interested?
Thanks
I want a tool where I can input XYZ, X, PlaceY and ProductZ just once and it fill it everywhere instead of having me manually edit the whole thing, and gives me an HTML content I can copy paste to my email client (Thunderbird)
Any advice on such a tool/or process
Thanks
using php is very easy
only need to add a PHP tags to open before the code and after de code to close it , i give you a function that can do what you want to do
/* " <?PHP" <- to open the tag, and, "?>" <- to close the tag */
<?PHP function sendemail($XYZ, $X, $PlaceY, $ProductZ, $emailto)
{
$subject = "your subject here";
$body = "<html><body>Hello $XYZ, I went to your Company $X in $PlaceY yesterday and was impressed. I want to propose to you $ProductZ. $XYZ would be benefited by $Productz <br><br><b>Subheading in Bold<b><br> Are you interested?<br><br>Thanks</body></html>";
$headers = "From: fromemail#yourdomain.com \r\n" ;
$headers .= 'Content-Type: text/html; charset=ISO-8859-1' . "\r\n";
"X-Mailer: php";
if (mail($emailto, $subject, $body, $headers))
{
return 1;
}
} ?>

Password protect a page, and send notification email when logged in

Is there a way to password protect a page with an array of passwords (which in this case is email addresses), and then once someone successfully logs in a notification is sent to a specified email address letting us know that someone has logged in with the given password (email address).
Thanks.
You have to do this with a server-side language like PHP. You can't do this with pure HTML and Javascript, unless you plan to store the usernames and passwords in a plaintext array in your Javascript (Don't do this, it is madness!).
If you use PHP, you can send the username and password data via POST, and have the user accounts stored in a MySQL Database. You can then lookup the username and password and see if they match, and if they do, then you could use something like PHP's mail() function to email the user.
As already mentioned, you'll need to use PHP, and your question unfortunately isn't something that can be answered in a couple of lines.
Below won't fully give you your answers, but it may lead you in the right direction to achieving them:
For a tutorial on user login using PHP $_POST , you could try here. Instead of reading the username and passwords from a mysql database, it would be simple enough to read in from an array defined in your PHP file.
For mail, below is a php function to email users their password once it's been reset. You should be able to get the idea of how the mail() function works from it and what variables to populate so you can change it for your own needs. You would call the email function once you've determined that a user has logged in succesfully.
public static function EmailPassword($user_email, $user, $password)
{
$mailfrom = "user#website.com.au";
$eol = "\n";
$content = $eol;
$content .= "Password for " . $user . " is " . $password . $eol;
$subject = "Pasword reset for " . $user . " at website.com.au";
$boundary = md5(uniqid(time()));
$header = 'From: '.$mailfrom.$eol;
$header .= 'Reply-To: '.$mailfrom.$eol;
$header .= 'MIME-Version: 1.0'.$eol;
$header .= 'Content-Type: multipart/mixed; boundary="'.$boundary.'"'.$eol;
$header .= 'X-Mailer: PHP v'.phpversion().$eol;
$body = 'This is a multi-part message in MIME format.'.$eol.$eol;
$body .= '--'.$boundary.$eol;
$body .= 'Content-Type: text/plain; charset=ISO-8859-1'.$eol;
$body .= 'Content-Transfer-Encoding: 8bit'.$eol;
$body .= $eol.stripslashes($content).$eol;
//send the email
mail($user_email, $subject, $body, $header);
}

PHP mail MMS attaching image not working

Hello guys I am working on webapplication for sending multimedia messages upon user input of their phone numbers. I am successfully able to send emails with images in HTML form. Now, I am trying to send my customers MMS via PHP mail function, but the only thing they receive is the link that I send them with the message.
Here is what I have come up with so far.
<?php
$email = '1234567890#somenetwork.domain';
$link = $_COOKIE["coupon"];
$to = $email;
$subject = 'Some Subject';
$message = " Hello, This is Testing Text 8.0
<a href=\"https://encrypted-tbn0.gstatic.com/images? \
q=tbn:ANd9GcS0dA2aipmy9hwAitgD8U5n8l_afNBvxYc3gnOFi7hOGoGAGIHssw\">Your Link</a> ";
$message->addAttachment("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcS0dA2aipmy9hwAitgD8U5n8l_afNBvxYc3gnOFi7hOGoGAGIHssw", "image/gif");
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: someone <support#someone.com>' . "\r\n";
mail($email, $subject, $message, $headers);
?>
When sending to a phone as MMS, you have to send the image as an attachment.
I found the following answer to be very helpful for easily sending attachments, even though it references "mail", not MMS:
Send attachments with PHP Mail()?
One of the issues is that you can't fetch that image in that fashion.
I.e. https://encrypted-tbn0.gstatic.com/images?\
q=tbn:ANd9GcS0dA2aipmy9hwAitgD8U5n8l_afNBvxYc3gnOFi7hOGoGAGIHssw
returns an empty file.
Also, since when can you send MMS via PHP's mail() function?
The most reliable way in my experience to send images via SMS/MMS is to send a WAP push msg.

Changing Font in autogenerated HTML e-mail message

I need to send a lot of numbers over so want to change the font to Courier.
HGow do I do this? My constructs are...
$message = "Contact : ".$_SESSION["Contact"]."\n\r".
...
$mail_sent = #mail( $to, $subject, $message, $headers );
When I try simple tests like bold on/off or spans suggested elsewhere they just appear as the text and are transmitted and appear identically in Outlook and my iPhone. Any ideas?
It seems that you are using php, so the next syntax should work. Just add the next headers to what you already have or replace the one you have with similar content:
$headers .= "Content-Type: text/html; charset=utf-8\r\n";
$headers .= "MIME-Version: 1.0\r\n";
And change your text to something like this:
$message = "Contact : "<span style="font-face:courier;">.$_SESSION["Contact"]<span>."\n\r".
I'm assuming that line is the one with the numbers you want to format. But of course you can modify any line in your message
Bye