I'm trying to implement this script to send email: <?php $to = "myemail@gmail.com"; $subject = "Test mail"; $message = "Hello! This is a simple email message."; $from = "myemail@gmail.com"; $headers = "From: $from"; $sentmail = mail($to,$subject,$message,$headers); // if your email succesfully sent if($sentmail){ echo "Email Has Been Sent ."; } else { echo "Cannot Send Email "; } ?> PHP: I ran the script using "php -q mail.php" and the output I have is Email Has Been Sent but I never get the email. any of you knows what can it be wrong?
Hi all, thank you phpl0v3r I have also this problem, but what is smtp server, and how to know if the server of my site has smtp or not ?
Telnet to port 25. If you can't connect then ask support if they are running it on another port. If you don't have an SMTP daemon installed locally - use googles. Search for 'PHP google smtp'. This is probably a better solution as googles SMTP servers are usually white listed, making the deliverability higher. Where as your hosting server probably has a few hundred more people sharing it, and if one of them decides to send out spammy messages - they've also blacklisted you.
please check the spam folder, may be ip of your host is blacklisted. If you need php email form PM me I will send you the working code.
Thanks all but I dont understand spam folder and how to see if my host is blacklisted so can u give me the details please ?
Basically, create a new testing page without form. setup some dummy variables. use a working example from online tutorials. and try it. some times your server requires return address too before sending an email actually. so you will have to define -r parameter with your returning email. if you need more assistance, PM me with your code and I will be able to help. thanks
use this mail function. <?php //Check whether the submission is made if(isset($hidSubmit)){ //Declarate the necessary variables $mail_to=$txtEmailto; $mail_from=$txtEmailfrm; $mail_sub=$txtSub; $mail_mesg=$txtMsg; //Check for success/failure of delivery if(mail($mail_to,$mail_sub,$mail_mesg,"From:$mail_from/r/nReply-to:$mail_from")) echo "<span class='red'>E-mail has been sent successfully from $mail_sub to $mail_to</span>"; else echo "<span class='red'>Failed to send the E-mail from $mail_sub to $mail_to</span>"; } ?>
I'd recommend against using mail() and going with PHPMailer's library. Chances are that anything sent by your server will be blacklisted or marked as spam unless you've setup a mailserver and can do signing from it. SMTP to a signed mail server will keep your messages out of spam and isn't hard to implement. A lot of hosting companies offer a SMTP server to use. It could also be from Gmail filtering out your message because it sees it as spam (fyi).