Jump to content


Photo

Mail() question


  • Please log in to reply
9 replies to this topic

#1 amalosoul

amalosoul
  • Members
  • PipPipPip
  • Advanced Member
  • 95 posts

Posted 16 October 2006 - 12:05 PM

I am using this code to send an email to yahoo. Can please somebody tell me what I am doing wrong?
<?php
$to="amalosoul@yahoo.com";
$subject="A new attempt";
$mess="This is a test message! \r\n http://army.ifastnet.com";
$timp=time();
$timp=date("r",$timp);
$headers="$timp \r\n To: amalosoul@yahoo.com \r\n From: myself@yahoo.com \r\n";

if(mail($to,$subject,$mess,$headers)) echo "ok!";
else echo "message not sent";
?>

Thank you in anticipation!

#2 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 16 October 2006 - 12:16 PM

Are you getting any errors...?

Well I see that you are declaring the to twice. You do not need them in the headers. Also, most servers require that the address that the mail is being sent from to be a known email address i..e you@yourdomain.com, and that you declare the from in the first part of the headers.

Good Luck,
Tom

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#3 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 16 October 2006 - 12:18 PM

You need to put Date: in front of time in the headers. Not sure if that is the problem, but try doing that.

#4 amalosoul

amalosoul
  • Members
  • PipPipPip
  • Advanced Member
  • 95 posts

Posted 16 October 2006 - 12:26 PM

First of all thank you for your replies.
Second of all I have tried this code as well but it still does not work:
<?php
$time=time();
$date=date("r",$time);
$to      = 'amalosoul@yahoo.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
	'Date: $date'."\r\n".
   'Reply-To: webmaster@example.com' . "\r\n" .
   'X-Mailer: PHP/' . phpversion();
if(mail($to,$subject,$mess,$headers)) echo "ok!";
else echo "message not sent";

?>


#5 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 16 October 2006 - 12:29 PM

can you send a message anyway?

have you setup php.ini to send messages?
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#6 amalosoul

amalosoul
  • Members
  • PipPipPip
  • Advanced Member
  • 95 posts

Posted 16 October 2006 - 12:34 PM

My host says that it can send emails, and I believe him (he only said he cannot sent emails to hotmail.com and all these internet providers that have something to do with microsoft, if I am not mistaken, but he said nothing about yahoo.com)

#7 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 16 October 2006 - 12:36 PM

Try this (from the manual) (edit the email to yours):
<?php
$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
   'Reply-To: webmaster@example.com' . "\r\n" .
   'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>

If it doesn't work, then contact your host.

#8 amalosoul

amalosoul
  • Members
  • PipPipPip
  • Advanced Member
  • 95 posts

Posted 16 October 2006 - 12:42 PM

Ok, thank you very much for your pacience!

#9 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 16 October 2006 - 08:30 PM

If you want to send html mail you may want to use these headers.

$to = "someone@something.com";
$subject = "Your Subject";
$message = "A simple <b>HTML</b> messsage";
$headers = "FROM: you@yourdomain.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: multipart/alternative;\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 7bit";
$headers .= "\r\n";
	   
if (mail($to, $subject, $message, $headers)) {
    echo "Your email has been sent";
}else{
    echo "We were unable to send your email. Please contact the web master";
}

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#10 amalosoul

amalosoul
  • Members
  • PipPipPip
  • Advanced Member
  • 95 posts

Posted 16 October 2006 - 09:26 PM

Thank you for your reply as well! I will try all possible ways of sending mails:)!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users