Im building an automated newsletter, im kinda stuck with this problem. I need to know if the email was sent or not. Here is my code
@$send = mail($emailRecipient, $subject, $message, $headers);
i tried to add it to an if statement but it does not work here is the code.
if( @$send = mail($emailRecipient, $subject, $message, $headers)){
//do something
}else{
//do something
}
Well mail() simply returns a boolean value depending on whether the mail was successfully accepted for delivery. From the php.net site: Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.
PHPMailer is a code library and used to send emails safely and easily via PHP code from a web server. Sending emails directly via PHP code requires a high-level familiarity to SMTP standard protocol and related issues and vulnerabilities about Email injection for spamming.
Make sure the localhost mail server is configuredWithout one, PHP cannot send mail by default. You can overcome this by installing a basic mail server. For Windows you can use the free Mercury Mail. You can also use SMTP to send your emails.
If it's still not working: change the sender ($sender) to a local email (use the same email as used for recipient). Upload the modified php file and retry. Contact your provider if it still does not work. Tell your provider that the standard php "mail()" function returns TRUE, but not mail will be sent.
if(@mail($emailRecipient, $subject, $message, $headers))
{
echo "Mail Sent Successfully";
}else{
echo "Mail Not Sent";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With