Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php - detect if email is sent

Tags:

php

email

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
}
like image 825
Kiel Avatar asked Jan 07 '13 07:01

Kiel


People also ask

How can I tell if an email is sent in php?

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.

How does php mailer work?

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.

Why is php not sending email?

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.

Why is mail function not working?

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.


1 Answers

if(@mail($emailRecipient, $subject, $message, $headers))
{
  echo "Mail Sent Successfully";
}else{
  echo "Mail Not Sent";
}
like image 147
Daya Avatar answered Oct 17 '22 08:10

Daya