Jump to content

How to send email through php


newbie8899

Recommended Posts

Hi, all.. i have a big problem here. I wish to send email through the php script.. but i don know what's wrong with it. it stated there email sent.. but i cannot receive any email. Can anybody tell me what probably did i do wrong? below is my test script which i use to test send the email.

 

<?php

//define the receiver of the email

$to = 'address@hotmail.com';

//define the subject of the email

$subject = 'Test email';

//define the message to be sent. Each line should be separated with \n

$message = "Hello World!\n\nThis is my first mail.";

//define the headers we want passed. Note that they are separated with \r\n

$headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";

//send the email

$mail_sent = @mail( $to, $subject, $message, $headers );

//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"

echo $mail_sent ? "Mail sent" : "Mail failed";

?>

 

after i run the script, the browser showing Mail sent. but when i check my email account, i did not receive any of this email. :'(

Link to comment
Share on other sites

Check your Junk folder, most of the time it goes there if your headers are wrong, if I am not mistaking.

 

 

Also, Try

<?php
//define the receiver of the email
$to = 'address@hotmail.com';
//define the subject of the email
$subject = 'Test email'; 
//define the message to be sent. Each line should be separated with \n
$message = "Hello World!\n\nThis is my first mail."; 
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";
//send the email
$mail_sent = mail( $to, $subject, $message, $headers );
  
  if($mail_sent){

  echo 'Email Was Sent';

}
else{

  echo 'Email was not sent';

}
?>

 

If/Else statement would make things much more simple.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.