0

PHP-beginner here trying to solve a problem for literally days now:

I'm trying to send html-mails with the PHP mail() function via the IONOS Mailserver. Html is important because I want to set the encoding for the e-mails in the header (special characters).

Somehow the script that I'm successfully using on other providers' servers isn't working on the IONOS servers. According to IONOS-support the e-mails weren't following the RFC5321 and RFC5322 standards.

I have been told to change my script and that the following field-types are required as a part of header: "Date:", "From:", "Sender:" and "To:" and these field-types must not be included more than once: "Date:", "From:", "Sender:", "To:", "CC:", "BCC:", "Subject:". Furthermore the field-type "Date:" has to be valid and following the RFC2822 standard.

Here is what I came up with:

$datum = date(DateTime::RFC2822);
$empfaenger = "info@xyz.de";
    
$headers   = array();
$headers[] = "Date: {$datum}";
$headers[] = "From: {$email}";
$headers[] = "Sender: {$email}";
$headers[] = "To: {$empfaenger}";
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=utf-8";
$headers[] = "X-Mailer: PHP/".phpversion();
mail("$empfaenger","Kontaktaufnahme via www.xyz.de von $name $vorname",$mailbody,implode("\r\n",$headers));

The variables missing here are defined earlier on.

Unfortunately this won't send the Mails via the IONOS-mailserver either.

Can anyone point out where I'm making the mistake? Thank you very much in advance!

Der Keim
  • 41
  • 8
  • 3
    _“Can anyone point out were I'm making the mistake?”_ - you are using PHP’s own native `mail` … The _best_ advice you can get on this, is use a proper mailer library. https://stackoverflow.com/questions/24644436/php-mail-function-doesnt-complete-sending-of-e-mail – CBroe Jan 13 '21 at 12:38
  • Thank you very much - I don't know whether I want to add more dependencies since this is a very simple website and a very simple contact form. If there is no other solution I will dive into this… – Der Keim Jan 13 '21 at 12:48
  • Is there any error message you could share with us? – Nico Haase Jan 13 '21 at 12:59
  • There is no error message. The form behaves as if the email is sent. When I use the form for plain text (delete the headers) everything works fine - except the character encoding. – Der Keim Jan 13 '21 at 13:01

0 Answers0