All the information are from a form. when submit the form, I use php mail() to send all the information to my email box, but I don't know how to format all the informatioin which from the submitted form.
is there a way to format the email which displays as the following style.
if using mail() can get that,how do i do? or there is another way to get that, thank you.
Don't use mail().
Instead use the phpmailer class.
http://code.google.com/a/apache-extras.org/p/phpmailer/source/browse/trunk/class.phpmailer.php
http://phpmailer.worxware.com/
You call the class in your code.
require "includes/class.phpmailer.php";
Then you format your mail strings using HTML and a bit of common sense. To format the way you want you can use p and line breaks. Images, links, most of what you would think to use in html. It has worked well for me.
Tip: You don't want to include external css so your html might have to be a bit old school with text-align and setting width in using style.
edited.
call the include
require "includes/class.phpmailer.php";
then, set a few variables such as your message ... do your formatting.
$mail = new PHPMailer();
$mail->IsMail();
$mail->AddReplyTo($emailAddress, "Your Reply Name"); // could be $replayemail if set
$mail->AddAddress($mailto); // who you are emailing
$mail->SetFrom($emailAddress, "Your From Name"); // from email
$mail->Subject = $subject; // keep it simple, email header
$mail->MsgHTML($message); // format fun stuff in $message
$mail->Send();
You need to learn about PHP HTML mail.
IMO best school for PHP beginners: http://www.w3schools.com/php/func_mail_mail.asp
Set the headers like this
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
mail($to,$subject,$message,$headers);
This would allow you to send html in mail.You can apply styling too.
Related
I am trying to send email using SMTP in Laravel everything is good but the html elements is coming along in the email body.
i.e.,
I am getting the below as mail
<h2>Welcome</h2><br><p>Hello user</p><br><p>Thanks</p>
Instead of
WelcomeHello userThanks
Here is my Code :
What is the thing i am missing to make it applied on the content of the email
$msg = "<h2>Welcome</h2><br><p>Hello user</p><br><p>Thanks</p>"
$message->setBody($msg);
$message->to('user#gmail.com');
$message->subject('Welcome Mail');
Try this...
$msg = "Welcome
Hello user
Thanks"
$message->setBody($msg);
$message->to('user#gmail.com');
$message->subject('Welcome Mail');
One possible solution is to wrap your HTML code in body tag.
Take a look at Laravel mail api too.
Seems like you want to send an email as HTML format:
mail($to, $subject, $message, $headers);
You will have to use the $headers parameter.
The last parameter, the headers, are optional for the function but required for sending HTML email, as this is where we are able to pass along the Content-Type declaration telling email clients to parse the email as HTML.
Source
Or, if you just want to add breaking lines and you leave HTML elements:
$msg = "Welcome \n Hello user \n Thanks"
Currently I'm writing a web interface which is full of data. I would like to export this data as an e-mail template, so you can edit the e-mail afterwards.
Is there a format such as *.oft, which can be read by all email programs?
I know that there is such a function in HTML (<a href="mailto:[...]">). Since the e-mail text is very long and I want to attach files, this doesn't seems to be a good solution.
Can someone help me?
There's no such format as you're looking for. The internet engineers who design email protocols and format concern themselves with what goes out over the network, but not with what's internal to the machine. Email is highly interoperable when sending and receiving messages as a result, but there's no analogous standards body for internal API's. Sometimes there are de facto standards that arise from a imitating the behavior of popular piece of software, but that hasn't happened for the email feature you're looking for.
Maybe you mean .EML files? I remember that this file can be opened with nearly all e-mail clients such as Outlook, Thunderbird etc.
As far as I can tell you can go one of two ways:
1 - Use a prebuilt solution such as the one by these guys at postageapp.com their API looks pretty simple and does everything you want to achieve.
2 - More time consuming, but you can create your own templete using PHP. I would go for something along these lines. This is a very simple way of doing it. You could write your own CSS in the head and go nuts. Just remember that tables are king when it comes to HTML email :) Once the template has been written, you could just pass through the $content to fill it....
sender.php
<?php
$email = "Hello, \n";
$email.= "Very <strong>impressed</strong> with your email! \n\n";
$email.= "Faithfully\n";
$email.= "Mr Example\n";
$to = "me#me.me"; // <-- Set this as yours for testing...
$from = "someone#nice.me";
$subject = "An email";
$headers = "From: Someone nice <" . $from . ">\r\n";
$headers .= "Reply-To: ". $from . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html><body>';
$message .= nl2br($email); // <---- if your email contains newline characters - it will convert them to <br />
$message .= '<br />www.example.com';
$message .= "</body></html>";
mail($to, $subject, $message, $headers);
// ADD LOTS OF PROTECTION IF NOT HARD CODING :)
?>
To extend this - if you for example use Gmail, then you could use Google's SMTP to send it - so that the email wouldn't say 'Sent on behalf of'.
Just create a email using HTML without CSS. Any data or binary can be passed through PHP and then emailed to the recipient.
To get you started, Create a file using fopen();. PHP has other functions that would allow you to edit, open, search&replace and even convert a file to a format of your choice. This is equivalent to a .oft file if not better, because all emails are be sent in text or a html equivalent regardless of the email client.
If you'd would like some more info on how to create this, let me know.
Here is what I need to do. I need to be able to dynamically generate custom emails. I have been using PHP's mail() function, but I have been encouraged to try phpmailer or Zendmail. But it doesn't seem to be able to handle custom emails.
What I need to do is be able to grab values from the form and insert them into the body of the message. I've been doing:
$message = '<html><body><p>First name: ' $first . '<br/><br/>';
$message .= ...(rest of message)
Then I do:
mail($recipient, $subject, $message, $headers); using the right headers for HTML.
Is there a way to do what I want with phpmailer or Zendmail? Is there a way to do this in OOP instead that might improve on what are getting to be very lengthy pages? I'd appreciate some guidance.
Using phpmailer you could try the code below.
$message = '<html><body><p>First name: '. $first . '<br/><br/>';
$mailer = new PHPMailer();
// other fields / properties
$mailer->Subject = $subject;
$mailer->AddAddress($receipient);
$mailer->IsHTML(true);
$mailer->Body = $message;
$mailer->Send();
you'd need to set the other fields for it to work properly though.
Yes, one of the main points of having a mail library is to be able to create complex emails (more easily). I would also recommend SwiftMailer.
http://swiftmailer.org
I have a php file that I am trying to send the output in a email using the php mail function (PHPMailer is not an option as the server I am working restricts their SMTP server). The code for the mail function is
$to = "xxx#example.com";
$subject = "Outdoor Grill Service Request";
ob_start();
require 'grill-form.php';
$body = ob_get_clean();
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers = "From: xxx#example.com\n";
mail($to,$subject,$body,$headers);
echo "Mail sent to $to";
grill-form.php is a php file that contains a html file that has tables that are populated with php variable from a form. This worked perfectly using PHPMailer but once I migrated over to standard php mail is got "screwy".
The issue I am running into is when the email sends I am getting raw HTML code and not the output of the grill-form.php (a styled table with values). I have little knowledge with the php mail function so I might be missing something stupid.
Was wondering what I am doing wrong. Thank you in advance for you help you people are the best.
Assuming that's your actual code, you're overwriting the $headers variable with the third declaration, not appending to what you have. The Content-type header is never making it in.
PHPMailer does support SMTP, by the way--what exactly do you mean by "restricts their SMTP server"? (Here's an example: http://phpmailer.worxware.com/index.php?pg=examplebsmtp)
I would like to send HTML email with graphic elements included. I have no idea to attach garaphics to this email.
You probably don't want to do an inline attachment by hand, it's far easier, and less error prone to use a library, like PHPMailer.
It can attach the inline images, or if you give it some HTML code, it will attach the images by itself and modify the code to display them.
You can try Swift Mailer
I'm not going to bore you with a mediocre explanation here so instead let me link to this great tutorial over at Sitepoint which explained it to me in plain English! - advanced-email-php
The short version is that you are probably best off creating a HTML formatted messages, and using the header parameter of the php mail function.
$headers = "From: sender#example.com\n" .
"MIME-Version: 1.0\n" .
"Content-type: text/html; charset=iso-8859-1";
mail(to#example.com, 'subject line', 'your message text <strong>with HTML in it</strong>', $headers);
The sitepoint.com article referenced by Jimmy provides an excellent and complete description of your options.