Jump to content

Recommended Posts

Help?!
My code:
[code]<?php
mail('[me]@gmail.com', 'My Subject', 'Testing');
?>[/code]
That's thye entire .php
I 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.net
What's going on? Why won't it work?

Thanks!
Link to comment
https://forums.phpfreaks.com/topic/19691-basic-mail-usage/
Share on other sites

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 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";
}
?>[/code]


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

Good luck,
Tom
Link to comment
https://forums.phpfreaks.com/topic/19691-basic-mail-usage/#findComment-85903
Share on other sites

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?
Link to comment
https://forums.phpfreaks.com/topic/19691-basic-mail-usage/#findComment-86005
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/19691-basic-mail-usage/#findComment-86012
Share on other sites

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..
Link to comment
https://forums.phpfreaks.com/topic/19691-basic-mail-usage/#findComment-86015
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/19691-basic-mail-usage/#findComment-86060
Share on other sites

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.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";
?>[/quote]
[move]Oops :)[/move]
Thanks for all the time and effort from you guys!
Link to comment
https://forums.phpfreaks.com/topic/19691-basic-mail-usage/#findComment-86126
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.