Is there a way to set the SMTP settings in php.ini, or somewhere else, to get the default mail() function to work with my office365 mail account? I prefer not to use API's like the PHPMailer.
The problem with PHP mailer is that it won't send out of the domain the website is hosted on, the error I get is: "Could not instantiate mail function."
Apart from that PHPmailer works fine, any idea how to fix this? When I change the "$to" line, I'll get the error.
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require '../../lib/src/Exception.php';
require '../../lib/src/PHPMailer.php';
require '../../lib/src/SMTP.php';
$to = 'info@***.nl';
$subject = 'PHPMailer GMail SMTP test';
$message = "test body";
$mailer = new PHPMailer;
//$mailer->isSMTP();
$mailer->SMTPDebug = 2; // 0 = off (for production use) - 1 = client messages - 2 = client and server messages
$mailer->Host = "smtp.office365.com"; // use $mailer->Host = gethostbyname('smtp.gmail.com'); // if your network does not support SMTP over IPv6
$mailer->Port = ***; // TLS only
$mailer->SMTPSecure = 'tls'; // ssl is depracated
$mailer->SMTPAuth = true;
$mailer->Username = '***';
$mailer->Password = '***';
$mailer->setFrom('noreply@***.nl','**',0);
$mailer->addAddress($to, '**');
$mailer->addReplyTo('info@**.nl','**');
$mailer->Subject = $subject;
$mailer->msgHTML($message); //$mailer->msgHTML(file_get_contents('contents.html'), __DIR__); //Read an HTML message body from an external file, convert referenced images to embedded,
$mailer->AltBody = 'HTML messaging not supported';
// $mailer->addAttachment('images/phpmailer_mini.png'); //Attach an image file
if(!$mailer->send()){
//echo "Mailer Error: " . $mailer->ErrorInfo;
echo 0;
}else{
echo 1;
//$_SESSION['mailerfeedback'] = "Bedankt voor je bericht!";
//header('Location: contact.php');
}