Jump to content

php mail function


kney

Recommended Posts

Why doesn't this send the mail?

 

if (isset($_POST['sendMail'])){
        $to = "[email protected]";
$subject = "TEST email";

$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags!</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
</table>
</body>
</html>
";

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";

// More headers
$headers .= 'From: <[email protected]>' . "\r\n";
$headers .= 'Cc: [email protected]' . "\r\n";

mail($to,$subject,$message,$headers);
}

Link to comment
https://forums.phpfreaks.com/topic/244504-php-mail-function/
Share on other sites

@WebStyles: The code above is the one I have now.

@PFMaBiSmAd: None of the code ever worked.

@AyKay47: Where can I configure the error logging?

 

 

 

add theses lines to the top of your script, this will print any errors you are receving directly onto your webpage

 

ini_set("error_reporting",E_ALL);
ini_set("display_errors","ON");

Link to comment
https://forums.phpfreaks.com/topic/244504-php-mail-function/#findComment-1255868
Share on other sites

Are you sure your $_POST['sendMail'] variable is set to that your code is even calling the mail() function?

 

At a minimum, you should have error checking logic in your code to test the value mail() returns and display a success or failure message so that you know the result of calling the mail function.

Link to comment
https://forums.phpfreaks.com/topic/244504-php-mail-function/#findComment-1255879
Share on other sites

This is the error i'm getting..

 

Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in \web\RecordDrivers\IndexRecord.php on line 322 Notice: Use of undefined constant mail - assumed 'mail' in \web\RecordDrivers\IndexRecord.php on line 323

Link to comment
https://forums.phpfreaks.com/topic/244504-php-mail-function/#findComment-1256245
Share on other sites

seems like you do not have an SMTP server set up on your localhost, in my opinion, i never encourage tampering with sending mail until your webpage is on a live server.. the host will provide the mail server for you.. however there are also third party mail servers out there

Link to comment
https://forums.phpfreaks.com/topic/244504-php-mail-function/#findComment-1256311
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.