0

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" />';
Anthony
  • 27
  • 7
  • 3
    *"The first issue is that some e-mail browsers, like gmail, are not displaying the images automaticly"* - Which everyone is glad it did its job. The user needs to click on the "Always display images from X-host" link in Gmail – Funk Forty Niner Aug 02 '16 at 15:52
  • *"The second issue is that the message is not using the style I put in

    "* - Did you instruct your mailer to send it out as HTML?

    – Funk Forty Niner Aug 02 '16 at 15:53
  • Hi Fred, thank you for your answer. As for the first issue, I completely understand that, however, I usually sent pre-formated emails from gmail but now I want to send them from a form (much easier!) - Is there a way it shows automaticly? As for the second issue, which part would you like me to post so we can verify that? Sorry again, I'm not totally familiar with this. – Anthony Aug 02 '16 at 15:55
  • you're quite welcome. Edit: ah, you edited your comment. – Funk Forty Niner Aug 02 '16 at 15:55
  • See my edited comment above – Anthony Aug 02 '16 at 15:56
  • 1
    *"Is there a way it shows automaticly?"* - No, as that would constitute as a breach of privacy/security (see my first comment on how it's possible). As for the second part; the whole thing ;-) Unable to give a full solution until I/we know *which animal(s)* we're dealing with here. ;-) – Funk Forty Niner Aug 02 '16 at 16:03
  • Hi, here's the whole thing linked to php mail() https://pastebin.com/nPq1jBFA – Anthony Aug 02 '16 at 16:07
  • that link expires in 6 days; I won't be here in 6 days *lol* – Funk Forty Niner Aug 02 '16 at 16:09
  • Hi, I'm hoping I'll have a solution to my problem within 6 days haha! – Anthony Aug 02 '16 at 16:11
  • "I am not using phpMailer because I am not familiar at all with it..." That sounds like a good reason not to send raw HTML email, since you're not familiar at all with *that*. Use a class like SwiftMailer or phpMailer. It'll save you grief and security issues. – ceejayoz Aug 02 '16 at 16:39

1 Answers1

0

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

Duane Lortie
  • 1,285
  • 1
  • 12
  • 16
  • Would this fix all my issues? – Anthony Aug 02 '16 at 15:58
  • You know, the OP was already aware of PHPMailer as they specifically stated : *I am not using phpMailer because I am not familiar at all with it* ... not saying you're wrong though, much easier than hacking about to get the MIME headers correct when using `mail()` (especially when sending multi-part). – CD001 Aug 02 '16 at 15:59
  • It'll be very hard for me to switch to PHPMailer, but if you tell me it will 1) Show my images in the e-mail message and 2) Respect the style I put in there... I don't mind at all trying it out. Just going to have a hard time haha. – Anthony Aug 02 '16 at 16:03
  • @Anthony Many bits of HTML won't work (or won't work the way you expect) in HTML email. Complex layouts basically must be built with nested tables like the 1990s, some clients will support some bits of HTML but not others, some clients will ignore media queries, etc. It is very complex and very frustrating. – ceejayoz Aug 02 '16 at 16:41