PHP mailer script won't work on IONOS Server

1.8k Views Asked by At

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 = "[email protected]";
    
$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!

1

There are 1 best solutions below

0
RCNeil On

Ionos/1and1 requires you routing the mail through their SMTP in order to send mail via PHP on their hosting. This can be difficult without a mailer library as the one comment suggests.

Here is how you would set them via PHPMailer:

$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host       = 'smtp.ionos.com';
$mail->SMTPAuth   = true;
$mail->Username   = '[email protected]';
$mail->Password   = 'your_password';
$mail->SMTPSecure = 'tls';
$mail->Port       = 465;

The details about using Ionos' SMTP can be found here - https://www.ionos.com/help/email/general-topics/settings-for-your-email-programs-imap-pop3/