Reputation: 21
I am having problems with my Phpmailer. For some reason it says Could not instantiate mail function. Could it be because of the From and Fromname? I have little to no experience in PhpMailer so it would be great if someone can help me!
<?php ob_start();
$naam= htmlspecialchars ($_REQUEST["nome"]);
$telefoon= htmlspecialchars ($_REQUEST["telefone"]);
$email= htmlspecialchars ($_REQUEST["email"]);
$woonplaats= htmlspecialchars ($_REQUEST["cidade"]);
$lengte= htmlspecialchars ($_REQUEST["altura"]);
$gewicht= htmlspecialchars ($_REQUEST["peso"]);
$streefgewicht= htmlspecialchars ($_REQUEST["ideal"]);
$leeftijd= htmlspecialchars ($_REQUEST["idade"]);
$hoe= htmlspecialchars ($_REQUEST["amigo"]);
$kanaal= htmlspecialchars ($_REQUEST["canal"]);
$commentaar= htmlspecialchars ($_REQUEST["comentario"]);
$waarover= htmlspecialchars ($_REQUEST["escolha"]);
//echo"$naam $telefoon $email $lengte $gewicht $streefgewicht $leeftijd $hoe $kanaal $commentaar $waarover";
require("class.phpmailer.php");
$naamgeadresseerde = "Karin Klaver";
$emailadres = "[email protected]";
//verstuur nieuwsbrief
$mail = new PHPMailer();
// Geef aan dat het een HTML mail betreft
$mail->IsHTML(true);
$mail->From = $emailadres;
$mail->FromName = $naamgeadresseerde;
$mail->AddAddress("$emailadres","$naamgeadresseerde");
$mail->AddCC("[email protected]", "K. Klaver");
$mail->AddBCC("[email protected]", "Mik Fetter");
$mail->Subject = "Reactie proefpakket4you.nl"; // Subject aanpassen
// Alternatieve body
$mail->AltBody = "Reactie proefpakket4you.nl";
$mail->Body = "
Naam: $naam <br>
Telefoonnummer: $telefoon <br>
E-mail: $email <br>
Lengte: $lengte <br>
Gewicht: $gewicht <br>
Streefgewicht: $streefgewicht <br>
Leeftijd: $leeftijd <br>
Hoe op deze site terechtgekomen (kennis): $hoe <br>
Hoe op deze site terechtgekomen: $kanaal <br>
Aanvullende opmerkingen: $commentaar <br>
Meer info/ Proberen / Starten: $waarover<br>
";
//$mail->WordWrap = 50;
if(!$mail->Send())
{
echo 'Er ging iets mis tijdens het versturen';
echo $mail->ErrorInfo;
}else
{
//vervolgstap zetten
echo"Goed gedaan";
header ("Location: http://www.proefpakket4you.nl/bedankt.php?naam=$naam");
}
?>
Upvotes: 1
Views: 3887
Reputation: 1040
Adding the option:
$phpmailer->IsSMTP();
made it more reliable for me.
Also it would be cleaner if you just used:
$mail->MsgHTML($body);
with $body as the html string instead of:
$mail->IsHTML(true);
$mail->Body = "
Naam: $naam <br>
Telefoonnummer: $telefoon <br>
E-mail: $email <br>
Lengte: $lengte <br>
Gewicht: $gewicht <br>
Streefgewicht: $streefgewicht <br>
Leeftijd: $leeftijd <br>
Hoe op deze site terechtgekomen (kennis): $hoe <br>
Hoe op deze site terechtgekomen: $kanaal <br>
Aanvullende opmerkingen: $commentaar <br>
Meer info/ Proberen / Starten: $waarover<br>";
also you can set From using (shouldn't need "quotes"):
$mail->setFrom($emailadres, $naamgeadresseerde);
Are you sending using a local mail server or a specific server? If you you would need something like:
$mail->Host = '127.0.0.1';
$mail->Port = 25;
for local host, or if sending through another server you might be required to provide login details to send using that email address, e.g:
$mail->SMTPSecure = "tls";
$mail->Host = 'smtp.microsoft365.com';
$mail->Port = 587;
$mail->Username = 'username';
$mail->Password = 'password';
Or it could also be what @Synchro said, and that you haven't set up a mail server on your computer....
Upvotes: 0
Reputation: 37700
This is likely to be because your server doesn't have a mail server installed or configured, or that your php.ini setting for sendmail_path
is wrong.
On a command line, can you send a message like this:
echo 'test' | mail -s 'test' [email protected]
If that doesn't work, php's mail function won't either.
If your sendmail path is wrong, you can either fix your ini file or switch to IsSendmail()
and provide the path in your script.
Upvotes: 1