Send HTML in email via PHP?

2018-12-31 06:45发布

How can I send a HTML format email with pictures using PHP? I want to have a page with some settings and a HTML output which is sent via email to an address. What should I do? The main problem is to attach files.how can i do that?

8条回答
旧人旧事旧时光
2楼-- · 2018-12-31 07:39

Simplest way is probably to just use Zend Framework or any of the other frameworks like CakePHP or Symphony.

You can do it with the standard mail function too, but you'll need a bit more knowledge on how to attach pictures.

Alternatively, just host the images on a server instead of attaching them. Sending HTML mail is documented in the mail function documentation.

查看更多
看风景的人
3楼-- · 2018-12-31 07:49

It is pretty simple, leave the images on the server and send the PHP + CSS to them...

$to = 'bob@example.com';

$subject = 'Website Change Reqest';

$headers = "From: " . strip_tags($_POST['req-email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
$headers .= "CC: susan@example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";

$message = '<p><strong>This is strong text</strong> while this is not.</p>';


mail($to, $subject, $message, $headers);

It is this line that tells the mailer and the recipient that the email contains (hopefully) well formed HTML that it will need to interpret:

$headers .= "Content-Type: text/html; charset=UTF-8\r\n";

Here is the link I got the info.. (link...)

You will need security though...

查看更多
登录 后发表回答