amalosoul Posted October 16, 2006 Share Posted October 16, 2006 I am using this code to send an email to yahoo. Can please somebody tell me what I am doing wrong?[code]<?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";?>[/code]Thank you in anticipation! Quote Link to comment https://forums.phpfreaks.com/topic/24086-mail-question/ Share on other sites More sharing options...
tomfmason Posted October 16, 2006 Share Posted October 16, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/24086-mail-question/#findComment-109463 Share on other sites More sharing options...
Daniel0 Posted October 16, 2006 Share Posted October 16, 2006 You need to put [tt]Date:[/tt] in front of time in the headers. Not sure if that is the problem, but try doing that. Quote Link to comment https://forums.phpfreaks.com/topic/24086-mail-question/#findComment-109466 Share on other sites More sharing options...
amalosoul Posted October 16, 2006 Author Share Posted October 16, 2006 First of all thank you for your replies.Second of all I have tried this code as well but it still does not work:[code]<?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";?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/24086-mail-question/#findComment-109468 Share on other sites More sharing options...
redarrow Posted October 16, 2006 Share Posted October 16, 2006 can you send a message anyway?have you setup php.ini to send messages? Quote Link to comment https://forums.phpfreaks.com/topic/24086-mail-question/#findComment-109471 Share on other sites More sharing options...
amalosoul Posted October 16, 2006 Author Share Posted October 16, 2006 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) Quote Link to comment https://forums.phpfreaks.com/topic/24086-mail-question/#findComment-109475 Share on other sites More sharing options...
Daniel0 Posted October 16, 2006 Share Posted October 16, 2006 Try this (from the manual) (edit the email to yours): [code]<?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);?> [/code]If it doesn't work, then contact your host. Quote Link to comment https://forums.phpfreaks.com/topic/24086-mail-question/#findComment-109476 Share on other sites More sharing options...
amalosoul Posted October 16, 2006 Author Share Posted October 16, 2006 Ok, thank you very much for your pacience! Quote Link to comment https://forums.phpfreaks.com/topic/24086-mail-question/#findComment-109479 Share on other sites More sharing options...
tomfmason Posted October 16, 2006 Share Posted October 16, 2006 If you want to send html mail you may want to use these headers.[code=php:0]$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";}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/24086-mail-question/#findComment-109720 Share on other sites More sharing options...
amalosoul Posted October 16, 2006 Author Share Posted October 16, 2006 Thank you for your reply as well! I will try all possible ways of sending mails:)! Quote Link to comment https://forums.phpfreaks.com/topic/24086-mail-question/#findComment-109739 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.