Jump to content


Photo

Basic mail() usage


  • Please log in to reply
10 replies to this topic

#1 yitzle

yitzle
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 04 September 2006 - 05:36 PM

Help?!
My code:
<?php
mail('[me]@gmail.com', 'My Subject', 'Testing');
?>
That's thye entire .php
I direct my browser to the php file and check my email. Hmm. Nothing.
<?php
@$test=mail('[me]@gmail.com', 'My Subject', 'Testing');
if ($test==1){
 echo('True');
} else {echo('False');}
?>
Well. I get 'True' but still no email.
I'm using 100webspace.net
What's going on? Why won't it work?

Thanks!

#2 tomfmason

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

Posted 04 September 2006 - 06:07 PM

You may want to check and see what your host requires for out going mail . I would do something like this

<?php
$to = "someone@something.com";
$subject = "A test message";
$message = "This is a test message. I am trying to
see if this mail function will work for me";

if (mail($to, $subject, $message, "From:You<you@yoursite.com>\nX-Mailer: PHP/" . phpversion())) {
     echo "You mail was sent";
}else{
     echo "Your mail was not sent";
}
?>


Some host's mail servers require the From: section to an address that is known to the mail server.

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 yitzle

yitzle
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 04 September 2006 - 06:34 PM

Tested your code
Not working :(

#4 tomfmason

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

Posted 04 September 2006 - 07:08 PM

Not working? Did you get an error?  Like I said you may want to contact your host. Are you makeing sure that the from portion of the code is a valid email address with the mail server?

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


#5 yitzle

yitzle
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 04 September 2006 - 07:14 PM

Erm... The mail() returns true
Can you elaborate on "Are you makeing sure that the from portion of the code is a valid email address with the mail server?"
Does it need to be valid format or a working address?
Does the @abc.com have to match the host's domain name?

#6 tomfmason

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

Posted 04 September 2006 - 07:54 PM

some mail servers require that the FROM you@yourdomain.com be a valid email address. This must be a address that is known to the server. For instance, webmaster@yourdomain.com or whatever.

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


#7 yitzle

yitzle
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 04 September 2006 - 09:39 PM

Sorry for being obtuse, but I don't follow.
My PHP is on 100webspace.net
The email is going to gMail.com
Who is imposing the From?
Is it gMail? And is gMail requiring it for be a recognized email address (e.g. a gMail address) or a valid @100webspace.net (which I don't have ATM)?
Or is it 100webspace?

#8 tomfmason

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

Posted 04 September 2006 - 09:47 PM

do you have a domain or is it a subdomain? If it is one of those free sites then they may not allow you to send mail at all. I would contact them and ask them if you are allowed to send mail via php and if so what requirements do you have to meet.

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


#9 radar

radar
  • Members
  • PipPipPip
  • Advanced Member
  • 645 posts
  • LocationSLC

Posted 04 September 2006 - 09:51 PM

Here is a working snippet from a site I am working on for work..

<?php

$msg = "Name: ".$_POST['name']."\nAddress: ".$_POST['address']."";
					if ($_POST['address2'] != "") {
					$msg .= "\nAddress 2: ".$_POST['address2']."";
					}
					$msg .="\nCity: ".$_POST['city']."\nState: ".$_POST['states']."\nZip Code: ".$_POST['zip']."";
					$msg .= "\nEmail: ".$_POST['email']."\nPhone Manufacturer: ".$_POST['makes']."\nPhone Model: ".$_POST['modelnum']."\nBlue Light?: ".$_POST['blue_light']."\nComments: ".$_POST['comments']."";
$from = "FROM: ".$_POST['email'];
mail('to@domain.com', 'faq form submission', $msg, $from);

?>

Okay so all of the $msg is taking contents of a form and putting them together into an email message.. 
$from is the person who is sending the email address..  it needs to be there otherwise it won't work right...  even if you just put in there 'FROM: myemail@mydomain.com' it will work...

It's really not that hard...  basically odds are you are going to have a form.. in this form you should ask for the persons email address -- when they input their email address this now becomes your from address..

#10 yitzle

yitzle
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 04 September 2006 - 10:52 PM

I am in fact using a form. And it does have a mandatory email field :)
However, I'm pulling my data by doing
$msg .= "From: " .$from;
where from is the name of the textfield on the form.

I'll send the admins an email about sending mail().
It is a subdomain setup, but I think I am allowed an email address at it.

#11 yitzle

yitzle
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 05 September 2006 - 02:40 AM

From the 100webspace.com PHP FAQ:

You can be having trouble sending e-mail using Formmail script, because of the following reasons:

1. You have entered an e-mail address which is not hosted on our servers. We require the one of either the 'FROM:' e-mail address or the 'TO:' e-mail address to be hosted on our servers. Only if one of them is hosted on our servers, you will be able to send e-mail successfully.

2. You are using wrong header information. You must always provide the text From:, the name of the sender and an e-mail address. Without one of these three parameters, the formmail script will not work properly and will not deliver e-mail to your mailbox. You can find out more information here: http://www.php.net/m...nction.mail.php

Here are examples of well working formmail scripts:

First Example:

<?
$from = "From: yourname ";
$to = "receiver";
$subject = "Hi! ";
$body = "TEST";

if(mail($to,$subject,$body,$from)) echo "MAIL - OK";
else echo "MAIL FAILED";
?>

Second Example:

<?
$from = "From: sender";
$to = "yourname ";
$subject = "Hi! ";
$body = "TEST";

if(mail($to,$subject,$body,$from)) echo "MAIL - OK";
else echo "MAIL FAILED";
?>

[move]Oops :)[/move]
Thanks for all the time and effort from you guys!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users