PHPMailer HTML with a variable using BCC - php

I am using PHPMailer, I have set it all up and working everything is fine, however I have run into a problem.
I need for each recipient to receive the HTML slightly different which is a link within the HTML email. So the link would have to change for each recipient.
I could simply use a php loop that sends it one by one to each recipient, however this will take a lot of processing and could time out the request I do not want this to happen.
Is there away I can use shortcodes using curly brackets as you would on most wysiwyg editors {email} so then I do $mail->send() once as oppose to loop through all of the recipients and do $mail->send() for each one, which I am trying to avoid.
If you need any more information I am happy to edit this question.
https://code.google.com/a/apache-extras.org/p/phpmailer/

I don't think you can do that using only PHPMailer. I had a look at the class methods, nothing linked to such a thing.
Worx International Inc. has another solution called PHPMailer-ML that could provide a good solution to your needs : http://phpmailer.worxware.com/index.php?pg=phpmailerml

Related

PHP mail() not sending email

I have a form on a webpage which emails the details using the PHP mail() function. The form is quite long, and I also am including HTML formatting for the email.
The email sends fine if I don't include all the form information, but when I try to include the whole form the email doesn't get sent. It seems to stop working when I'm including too much information. As soon as I take some of the information out it works again, and it doesn't matter which part of the information I remove.
I have tried the form on two different website hosts with the same problem. The content for the email is only about 300 lines long so I'm not sure if size is the issue.
Does anyone know what might be causing the problem?
here is my code for your reference
When I say "stop working" above, I mean simply that the mail() function returns false and does not send the email. The actual form works fine.
When you come to that amount of HTML within a PHP-script it is useful to catch it in a variable instead of putting every single line in a $body variable.
ob_start();
?>
<html>
Your HTML.
</html>
<?
$body = ob_get_clean();
This way you can easier see if there is something wrong with your message ruining the mail-function.
Here is a description of the php mail function. This document along with this document, What is the PHP Mail Character Limit, specifies that each line of the body must be no longer than 70 characters.
This stackoverflow, What is the maximum length of a string in PHP, as well as other sources indicate that PHP does not have a specific limit other than total memory limits which your string appears to be well under.
Also there are several different places where there could be a failure and you do not specify the behavior you are seeing for a failure.
First of all, check the return value of mail() to determine if PHP was able to hand the message off to the mail agent, the MTA. Next make sure that you specify good to and return addresses so that if there is a problem in the mail agent, it will be able to send you some kind of a reply describing the problem.
An elaboration of the answer provided by Undrium above. Here are some links to additional materials based on his answer.
Here is the ob_get_clean() documentation.
Here is an example using ob_get_clear() with sending HTML Email.

Include whole page in php mail

Is it possible to include a separate html page in a php email?
Example, create a separate page that has all the content on it I want to email it and then include it in a php mail() on another page as the message?
Thanks
If you meant sending HTML email, yes. You can do that. You just need to add additional headers in the fourth parameter of mail() and pull the information from the HTML file you have using file_get_contents(). Please check this:
http://css-tricks.com/sending-nice-html-email-with-php/
Yes, it's possible exactly how rationalboss explained. Personally I use PEAR for html emails. It's a pain to get started with if you're not familiar to PEAR, but life has improved once I got it going.
Careful though, html/css does not have the same support in email clients that it does in browsers. You can create a beautiful page and find out that most people receive it with huge glitches due to certain CSS rules being ignored.
Best practice last I heard is to keep it simple and use inline styles for everything. Avoid floats and positioning. In fact, I believe it is actually still safer to use tables when dealing with email layouts if you need things to sit next to each other.
And then test in as many email clients as you can. Then cry and try to fix things.
I hear good things about Email on Acid for testing. It's a pay service but they offer a limited test for 3 clients as well.
If you're just doing a relatively simple email then it shouldn't be too bad. But if you're trying to make something that really looks great I recommend doing some googling on styling html specifically for emails.

What is the best way for creating default emails?

I'm planing on using PHPMailer which comes along with Wordpress.
I will be submitting HTML e-mail including alternative txt mail using SMTP.
I will have different e-mails depending on user action (registration, request etc).
I'm not sure if this is the best way, but I'm thinking of creating a folder containing HTML files, e.g. /emails/confirm_registration.html.
Then I will fetch the content and put it in the body of the mail $mail->Body=$message;
I also want to include variables such as the users name in the body text.
So this is my question:
Should I put the body text inside a function, call it with parameters and then return content?
Or should I add placeholders like {first-name} in the HTML and use str_replace('{first-name}','Some name') once I've returned the html content?
If you have better suggestions, I would greatly appreciate that.
May I suggest you use SwiftMailer as your email library
http://swiftmailer.org/
This library is really stable, elegant and complete. Your method of replacing placeholders with text is standard and works, if I recall many common templating libraries like smarty for example use a very similar methodology.
I always use this method in my custom programming, it seems perfect to me.

'Raw-send' using PHPmailer?

I need to write a PHP script that can insert one (or more) additional header, and re-send it to another email address.
How would I do that using PHPmailer? I can't seem to find how to do a 'raw send' of email message (with additional headers inserted already).
Or, if PHPmailer can't do that, how do you recommend I do what I want?
After spelunking around, I decided to just use 'fsockopen' and adapt this PHP snippet (lots of bugs there).
Thanks for everyone commenting!

PHP mail not showing up on email

I have created a small script that sends a multipart email via php the mail() (that has been a challenge in itself!).
When I test the script and send and email it all works fine, but when I try another address (one which has the same domain as the server) the email appears blank. All the content is there when you look at the raw code, but nothing displays.
I solved the problem by removing the doctype tag from the code and left everything bare coded.
I also noticed the php variable
$body=' (html code here) '
The whitespace after ' was causing the email to show up empty sometime... I'm not exactly sure why!
I have encountered a similar issue and it was because I had a website www.example.com sending an email to me#example.com but the web server and email servers were on different machines. I had to ask the host to sort it so that the website wouldn't try to route emails within the server itself.
I managed to sort this by changing my own code to instead using something a little more supported - phpMailer.
I found this very easy to use and install into my own code. Also giving me as much flexibility as I had with my original code.
I guess though this isn't sorting the original problem, but it did seem to sort on my code.

Categories