Jump to content

Mail() question


amalosoul

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!
Link to comment
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
Link to comment
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]
Link to comment
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.
Link to comment
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]
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.