yitzle Posted September 4, 2006 Share Posted September 4, 2006 Help?!My code:[code]<?phpmail('[me]@gmail.com', 'My Subject', 'Testing');?>[/code]That's thye entire .phpI direct my browser to the php file and check my email. Hmm. Nothing.[code]<?php@$test=mail('[me]@gmail.com', 'My Subject', 'Testing');if ($test==1){ echo('True');} else {echo('False');}?>[/code]Well. I get 'True' but still no email.I'm using 100webspace.netWhat's going on? Why won't it work?Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/19691-basic-mail-usage/ Share on other sites More sharing options...
tomfmason Posted September 4, 2006 Share Posted September 4, 2006 You may want to check and see what your host requires for out going mail . I would do something like this[code]<?php$to = "someone@something.com";$subject = "A test message";$message = "This is a test message. I am trying tosee 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";}?>[/code]Some host's mail servers require the From: section to an address that is known to the mail server.Good luck,Tom Quote Link to comment https://forums.phpfreaks.com/topic/19691-basic-mail-usage/#findComment-85903 Share on other sites More sharing options...
yitzle Posted September 4, 2006 Author Share Posted September 4, 2006 Tested your codeNot working :( Quote Link to comment https://forums.phpfreaks.com/topic/19691-basic-mail-usage/#findComment-85911 Share on other sites More sharing options...
tomfmason Posted September 4, 2006 Share Posted September 4, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/19691-basic-mail-usage/#findComment-85921 Share on other sites More sharing options...
yitzle Posted September 4, 2006 Author Share Posted September 4, 2006 Erm... The mail() returns trueCan 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? Quote Link to comment https://forums.phpfreaks.com/topic/19691-basic-mail-usage/#findComment-85926 Share on other sites More sharing options...
tomfmason Posted September 4, 2006 Share Posted September 4, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/19691-basic-mail-usage/#findComment-85948 Share on other sites More sharing options...
yitzle Posted September 4, 2006 Author Share Posted September 4, 2006 Sorry for being obtuse, but I don't follow.My PHP is on 100webspace.netThe email is going to gMail.comWho 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? Quote Link to comment https://forums.phpfreaks.com/topic/19691-basic-mail-usage/#findComment-86005 Share on other sites More sharing options...
tomfmason Posted September 4, 2006 Share Posted September 4, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/19691-basic-mail-usage/#findComment-86012 Share on other sites More sharing options...
radar Posted September 4, 2006 Share Posted September 4, 2006 Here is a working snippet from a site I am working on for work..[code]<?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);?>[/code]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.. Quote Link to comment https://forums.phpfreaks.com/topic/19691-basic-mail-usage/#findComment-86015 Share on other sites More sharing options...
yitzle Posted September 4, 2006 Author Share Posted September 4, 2006 I am in fact using a form. And it does have a mandatory email field :)However, I'm pulling my data by doing [code]$msg .= "From: " .$from;[/code] 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. Quote Link to comment https://forums.phpfreaks.com/topic/19691-basic-mail-usage/#findComment-86060 Share on other sites More sharing options...
yitzle Posted September 5, 2006 Author Share Posted September 5, 2006 From the 100webspace.com PHP FAQ:[quote]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/manual/en/function.mail.phpHere 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";?>[/quote][move]Oops :)[/move]Thanks for all the time and effort from you guys! Quote Link to comment https://forums.phpfreaks.com/topic/19691-basic-mail-usage/#findComment-86126 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.