php mail() function: How to display images and use

2019-03-05 14:35发布

This question already has an answer here:

I'm currently having an issue with the php mail() function. The first issue is that some e-mail browsers, like gmail, are not displaying the images automaticly. The second issue is that the message is not using the style I put in <p style>

Here is the code only for the 'message' part of the php mail() function. The rest isn't needed (and if it is, please let me know).

I am not using phpMailer because I am not familiar at all with it, I'm very beginner in code and finally this part of the code is a little part of a script.

$message = '<html><body><center>';
$message .= '<img src="http://externet.website/mail/images/logo.png" alt="Mogingo" />';
$message .= '<br /><p />';
$message .= '<img src="http://externet.website/mail/images/orangebar.png" alt="Spacer" />';
$message .= '<p style="font-family:"Comic Sans MS";font-size:60px"><strong>Bonjour!</p></strong>';
$message .= '<p style="font-family:"Sans Serif";font-size:22px">Merci d’avoir utilisé les services de gestion de projet de Mogingo, nous apprécions votre confiance. Votre facture est disponible en cliquant sur lien ci-dessous:</p>';
$message .= '<p style="font-family:"Sans Serif";font-size:22px">';
$message .=  $_POST['URL-main'];
$message .= "</p>";
$message .= '<p style="font-family:"Sans Serif";font-size:22px">Si vous avez apprécié l’expérience, n’hésitez pas à en parler dans votre réseau : nous avons un programme de récompense de 10% de rabais sur votre prochaine facture lorsque vous nous référez un nouveau client !';
$message .= '<p style="font-family:"Sans Serif";font-size:22px">Au plaisir de faire affaires avec vous,<p>';
$message .= '<p style="font-family:"Sans Serif";font-size:22px">- L’Équipe de Mogingo</p>';
$message .= '<img src="http://externet.website/mail/images/orangebar.png" alt="Spacer" />';
$message .= '</body></center></html>';

Thank you for taking time to read and hopefully provide answer.

EDIT

I have fixed my issue of showing my images the following way: - I now use PHPMailer which is much more easier. - You need to add the following lines

$mail->AddEmbeddedImage("../images/logo.png", 'logo');

and then you can refer to that image using

$message .= '<img src="cid:orangebar" alt="Spacer" />';

1条回答
时光不老,我们不散
2楼-- · 2019-03-05 15:05

Sounds like a job for PHPMailer.. http://phpmailer.worxware.com/ Once installed, use the examples like this one http://phpmailer.worxware.com/index.php?pg=exampleamail to construct an HTML email with inline attachments

查看更多
登录 后发表回答