Jump to content

Archived

This topic is now archived and is closed to further replies.

amalosoul

Mail() question

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
can you send a message anyway?

have you setup php.ini to send messages?

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

×

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.