I'm trying to send a simple email in PHP. I've stripped it back to the basics and it's still failing. I used to do this fine?
Any ideas?
mail('myemail@gmail.com', "Subject Line","Body") or die ('Error Sending Email.');
I keep getting the error.
I'm trying to send a simple email in PHP. I've stripped it back to the basics and it's still failing. I used to do this fine?
Any ideas?
mail('myemail@gmail.com', "Subject Line","Body") or die ('Error Sending Email.');
I keep getting the error.
Add a "From" header with a valid email address on the web server?
Done that, here's my original function
function sendEmail($i_email, $i_subject, $i_BookingCode, $i_CustomerName){
$to = $i_email;
$subject = $i_subject;
$headers = "From: bookings@mydomain.com\r\n";
$headers .= "Reply-To: bookings@mydomain.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html><body>';
$message .= '<img style="width: 100%;" src="images/header.png">';
$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= "<tr style='background: #eee;'><td><strong>Booking Code:</strong> </td><td>" . $i_BookingCode. "</td></tr>";
$message .= "<tr><td><strong>Customer Name:</strong> </td><td>" . $i_CustomerName . "</td></tr>";
$message .= "</table>";
$message .= "</body></html>";
mail($to, $subject, '$message', $headers) or die ('Error Sending Email.');
}
Wondering if there's something in the .ini file I need to enable?
No guarantees, but maybe try:
... or die("<pre>Error Sending Email:\n".print_r(error_get_last(), 1)."</pre>");
Nothing glaringly wrong with what's posted (as NogDog suggests, there may be more information available about the error). Once the mail is delivered there will be a new problem because the body will simply be '$message
'. Also, it might be tidier to pass an array of headers rather than building up a string (assuming you're using a version of PHP that's less than three years old).
Thanks, I'm following the example here (https://github.com/PHPMailer/PHPMailer) and it's working.
I get a heap of output though.. multiple lines starting with.
2020-08-04 02:43:23 SERVER -> CLIENT...
But I can't see where the output is coming from
nzkiwi80 But I can't see where the output is coming from
Maybe this line is responsible?
$mail->SMTPDebug = SMTP::DEBUG_SERVER; // Enable verbose debug output
I haven't read the documentation, though; I'm just guessing: I wouldn't expect a readme example to be the final word on how to use the package.
Yeah, it's the debug. There are a few levels of debug as well as none at all - obviously you'll want to turn it off on production. However, if you run into trouble it's full of actual useful information.