-1

Years ago someone made this PHP script for me. I use it on dozens of web pages. Recently my hoster was taken over by another company and my script stopped working after that. The helpdesk of the new hoster gave me a tip to look at:

How to send an HTML email using SMTP in PHP

You can use the hostname below in the article above: $host = "mail.argewebhosting.nl";

However, I am not a php specialist and I would like to be able to modify it myself. Can someone tell me what I can do to get the script working again?

==========================================================

<?php
if (!isset($_POST['naam_inzender']) || !isset($_POST['emailadres_inzender']) || !isset($_POST['opmerkingen'])) {
echo 'U heeft niet alle velden ingevuld!';
exit;

}

$naam = htmlspecialchars($_POST['naam_inzender']);
$email = htmlspecialchars($_POST['emailadres_inzender']);
$bericht = htmlspecialchars($_POST['opmerkingen']);
$organisatie= htmlspecialchars($_POST['organisatie']);
$plaats_organisatie= htmlspecialchars($_POST['plaats_organisatie']);
$email_onderwerp= htmlspecialchars($_POST['email_onderwerp']);
$auteur= htmlspecialchars($_POST['auteuradres']);
$header = "From: ".$naam."<$email>\r\n";
$tijd = time();
$datum = strftime('%d/%m/%y %H:%M', $tijd);
$ip = getenv('REMOTE_ADDR');
$message = $naam.' -'.$organisatie.'-'.$plaats_organisatie.'- met het e-mailadres '.$email.' en het IP '.$ip.' stuurde op '.$datum.' het volgende bericht:

____________________________________

'.$bericht.'

------------------------------------';

if(mail($auteur, $email_onderwerp, $message, $header))
header("Location: https://www.website.nl/opmerkingen.htm");
else
echo 'Niet verstuurd';
?>

===========================================================================

1 Answers1

3

The problem in your script is that you are using the mail() PHP function, which requires a Mail Transfer Agent on the web server configured to send email.

Evidently the new hosting provider has decided (and I cannot blame them) to block all email originating from non-authenticated MTAs, and to force every hosted website to use the correct email procedure to send emails.

You need an SMTP server available (refer to your hosting provider, maybe they already have one ready for this kind of issue), and you need to replace the mail() command with a PHP mail sender library, I can suggest something like PHPMailer (https://github.com/PHPMailer/PHPMailer) which has a nice tutorial to get you started, and it's pretty frequently updated.

Fanfurlio
  • 216
  • 2
  • 7