Sending html mails with PHP - php

So i am using xmail php class to send my mails.
Now that i have quite some users on my site, some user's mail does not have html enabled for their emails. Is there any way I can write a message at the top of the email, or even show another email content, if they view it as text/plain?
If not, what are my options, what can I do? I know one option and that is sending text/plain mails, but these wont even allow html anchor links, which I need for e.g activation mails..

You can send multi-part emails. One part is HTML and then there is a fallback of plain text for non HTML email clients. PHPMailer makes this easy to do.

Related

Adding an image in email headers PHP

I want to add an image in the mail headers just like Youtube has when I receive an email from them. I'm simply using the php mail function to send emails, but I can't figure out how to implement this. Am I thinking it wrong?
Here is the final result I want
Thanks for your time,
Felix
You can pass HTML as body in your email.
The only problem is that outlook does not support it.
But all you have to do is build your email body in html and send it using PHP.
For the header it looks more like an tag or something, maybe it's not send via PHP. you could check out software like mailchimp.
P.S. make sure your image is hosting somewhere because you can't access it localy.

Make phpmailer() send a rich text or plain text email - not an html

Im trying to send messages to a mail account that will only accept rich, or plain text emails. Im aware of the AltBody method, but i want to send the message primary as a rich or plain text email.
Ive looked through the docs but couldn't find an answer, does any one know how i can achieve this ?
Place the HTML (rich) version to normal body and plaintext version to AltBody. Then send the mail as HTML. PhpMailer will send both bodies; clients capable of displaying HTML will display it, others should display plain text version.

Can newsletter content be generated with PHP?

I manage a live music venue's newsletter and the show listings/calendar on the main site are generated using PHP. Is there a way to generate content in newsletters via php?
Example, I create the newsletter.php file, upload the code to our newsletter service provider, and when someone opens the message, the latest listings are available in their email.
As of now, I'm only seeing a portion of the php code where I'd like to see the calendar...
You can generate the content of an e-mail with any scripting language, but only before sending it. Once the e-mail has been sent, it has to be in a format that e-mail clients understand (such as plain text or HTML).
It's also very easy to send email with php, with the mail function.
You could generate the email from your php template, and if it looks how you want it to, click a button and send that email to the people on your mailing list.
It sounds like you have a newsletter-delivery service in place, but this is another option.

PHP send mail with attachment AND html template

my question is simple...
I have coded the send HTML mail, and plains with attachment but what about HTML with attachments? my header has to be content-type:multipart/mixed; and that doesn't work for HTML messages.
Thanks!
Use something like PHPMailer or SwiftMailer. it's trivial to send out dual html + plaintext emails with attachments and embedded images with either of them, and they're both free and easy to install/use.

How can I create an email newsletter by taking objects from a database?

Well, I'm trying to create a newsletter, that will send emails to users in a database. The newsletter itself would draw "events" and other activities from a database. Whats the best way to take that list, and put them in an email? I was thinking about putting them into an html page, then sending an html email, but not all emails support html(like school email). What would your guys recommend? Could you point me to some good resources?
Also, this is for a school project, so I cant use any open source type stuff, unfortunately :(
You are correct in your assumption that if you are creating html newsletters, you will also have to do a text based version for clients that don't support html or ones that ask to have e-mail be sent only in text. You will need to make sure your code sends both versions to recipients. You could also ask the recipients for their preference and send them the specific version that they requested.
For html e-mail it is highly recommended to read the following two articles by CampaignMonitor (they specialize in e-mail marketing sofware):
HTML E-mail Design Guidelines
Guide to CSS support in email
clients
Note that I am assuming you are asking for help with the actual construction of the html for the email not the code needed to create and send the newsletter.
Good luck with your project.
==== UPDATE ====
So it seems that you actually need help in developing this project. Since this is a homework, I will provide some general advice that should steer you in the correct direction and get you started on the project. Then, if you have any specific problems with your code, you can ask about them on Stackoverflow.
There is really two things that need to be done here:
In PHP, dynamically contruct a variable that contains the html or text versions of the e-mail that needs to be sent.
Loop through your contact list and e-mail the contents of that variable.
Sending E-mail
I will start with the sending e-mail portion, because the links provide bellow also show you how to construct the message. Also, in your comment you said you already know how to contruct an html from a database. The following links show you two ways to send e-mail. You can either use the Mail function that comes with PHP or download the PEAR_Mail package. If you are allowed to use additional libraries and want to send html e-mail, I would recommend using the PEAR_Mail, because it makes things much easier if you want to send a both an html and text version of an e-mail together.
Note: To send an e-mail you will need to use some sort of mail server. If you are using Windows, you can install the SMTP service that comes with IIS or you can use an external smtp service such as google to send your e-mails.
http://www.w3schools.com/php/php_ref_mail.asp
http://us2.php.net/manual/en/function.mail.php
http://www.webcheatsheet.com/php/send_email_text_html_attachment.php
http://pear.php.net/manual/en/package.mail.mail.php
http://pear.php.net/package/Mail_Mime/docs
Construct E-mail
The complexity here will depend on whether you just want a plain text e-mail or html. For either case you will need to read the event data from your database and add it to the message that you want to send.
Some Seudocode:
Loop through datarows
message = DataRow[EventDate] + " " + DataRow[EventName] + "\n"
Loop through recipients
mail message
Hopefully this gives you a start. I would recommend getting php to send out an e-mail of a static html or text first. Once you have that code working you can start working on adding the functionality of reading event info from a database and sending it out.
Hope this helps.

Categories