is php mail() function working?

web.houstontoh88

New Member
Messages
6
Reaction score
0
Points
0
is php mail() function working?
i have a registration script that send applicants an email when registering. Was testing by sending to my personal email but the mail doesnt get sent. my script is absolutely as it returns true when mail() is invoked.
 
Last edited:

mrnutt

New Member
Messages
9
Reaction score
0
Points
0
no it is sent to send to me.

Here is a basic working contact form in php using mail()

Code:
<?php
function spamcheck($field)
  {
  //filter_var() sanitizes the e-mail
  //address using FILTER_SANITIZE_EMAIL
  $field=filter_var($field, FILTER_SANITIZE_EMAIL);

  //filter_var() validates the e-mail
  //address using FILTER_VALIDATE_EMAIL
  if(filter_var($field, FILTER_VALIDATE_EMAIL))
    {
    return TRUE;
    }
  else
    {
    return FALSE;
    }
  }

if (isset($_REQUEST['email']))
  {//if "email" is filled out, proceed

  //check if the email address is invalid
  $mailcheck = spamcheck($_REQUEST['email']);
  if ($mailcheck==FALSE)
    {
    echo "Try Again";
    }
  else
    {//send email
    $email = $_REQUEST['email'] ;
    $subject = $_REQUEST['subject'] ;
    $message = $_REQUEST['message'] ;
    mail("YOUREMAIL", "Subject: $subject",
    $message, "From: $email" );
    echo "Thank you, your email has been sent.";
    }
  }
else
  {//if "email" is not filled out, display the form
  echo "<div style='padding:5px;'><form method='post' action='contact.php'>
  Email: <input name='email' type='text' /><br />
  Subject: <input name='subject' type='text' /><br />
  Message:<br />
  <textarea name='message' rows='15' cols='40'>
  </textarea><br />
  <input type='submit' value='Send' />
  </form></div>";
  }
?>
save as contact.php
 
Last edited:

vv.bbcc19

Community Advocate
Community Support
Messages
1,524
Reaction score
92
Points
48
is php mail() function working?
i have a registration script that send applicants an email when registering. Was testing by sending to my personal email but the mail doesnt get sent. my script is absolutely as it returns true when mail() is invoked.

The best tutorial (I think) is put here.
This worked for me.I put that on my sites too.
http://www.w3schools.com/PHP/php_mail.asp

Regs,
VVBB
 

ritimao50

New Member
Messages
5
Reaction score
0
Points
0
do i have to set up anything to use the email provided by x10hosting in this function ?
 

bidzey75

New Member
Messages
53
Reaction score
0
Points
0
no it is sent to send to me.
mail("YOUREMAIL", "Subject: $subject", $message, "From: $email" );
[/CODE]save as contact.php

is this literally the code, because "YOUREMAIL" is not defined anywhere. Perhaps your just hiding the email for posting purposes?

Also if you use $_REQUEST you have no guarantee that the data came from the post data, which leads to security holes in your script. Use $_POST to grantee that's not the problem.
 

stpvoice

Community Support Rep
Community Support
Messages
5,987
Reaction score
212
Points
63
Mail doesn't work unless content type is defined as text/plain.
 

Tarzan

New Member
Messages
66
Reaction score
0
Points
0
is php mail() function working?
i have a registration script that send applicants an email when registering. Was testing by sending to my personal email but the mail doesnt get sent. my script is absolutely as it returns true when mail() is invoked.

Are you trying to send to hotmail? I've had problems with hotmail accounts and x10 emails. It seems like hotmail doesn't accept emails from x10. (same problem with yahoo I think).
I don't know if that's the case anymore, but that was the problem last time I tried.

The solution I use is sending hotmail emails using gmail's mail servers.
 

bidzey75

New Member
Messages
53
Reaction score
0
Points
0
I'm using hotmail for my account, it's seems like it takes a few more minutes to receive the email then it goes into the junk box, once you tell it it's not junk it seems to work better, but it does work with Hotmail.

Mind you I got my forum (phpbb) configured with the SMTP parameters that was given to me by X10 when I signed up. And it sends the emails to Hotmail just fine. I gues when you use email() directly in a php script your using the servers configs that you're on. That may be a difference... not sure.
 

stpvoice

Community Support Rep
Community Support
Messages
5,987
Reaction score
212
Points
63
Personally, I use google apps with SMTP wherever possible.
php mail on all servers sends to gmail with no issues. I've got test scripts on each server that send to gmail no problems.
I'm not sure about hotmail, but I'm fairly sure the same applies for yahoo.
 

bidzey75

New Member
Messages
53
Reaction score
0
Points
0
if I remember correctly PHPBB was not sending the emails to Hotmail until I specified the SMTP parameters. But I didn't test it on my gmail account. If your hard-up for it I guess someone could always use the PEAR email class. Then you can specify the SMTP you want to use right in your php script.
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
Last time I checked, PEAR is not installed. So, you would have to install the basic PEAR files first.

PHPMailer works with Google/SMTP without needing to do download anything else. It is what I use.
 

anders0nge018

New Member
Messages
5
Reaction score
0
Points
0
As a noob to php scripting i have a ton of questions:

why doesn't my mail() work? i get a fail with a pretty basic script...

when i run mail() it fails and yet i'm doing nothing fundamentally different than mrnutt and the tutorial example that is linked by vv.bbc19...

Code:
<?php

// mail example (doesn't work - no mail server???)

$to = "???????@tmrsoft.x10.bz";
$subject = "Test Mail";
$message = "Hello! This is a simple test email!";
$from = "???????@tmrsoft.x10.bz";
$headers = "From: $from Content-type: text/plain";
if(!mail($to, "Subject: $subject", $message, $headers))
	echo "mail error<br/>";
else
	echo "mail sent<br/>";

?>

i'm sending an email to myself, i gave up on sending to my gmail account.

i just added the Content-type: text/plain line because someone said that would make it work - but again no dice.

I suspect that i can't access the mail server unless i'm making an obvious error in my code that I can't see. So, is there anythiing i need to do to make this work, i've wasted days on this. I assumed that everything is configured properly but obviously i'm wrong, any help would be greatly appreciated.
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Also if you use $_REQUEST you have no guarantee that the data came from the post data, which leads to security holes in your script. Use $_POST to grantee that's not the problem.
Post data is no more secure than query string data or cookies. All can be set by the user, and the POST method is still vulnerable to XSRF. The problem with using $_REQUEST is that you can have key collisions between the different sources and get the wrong value. By default, cookies override POST data override query string data.
 

anders0nge018

New Member
Messages
5
Reaction score
0
Points
0
nevermind got it to work... i didn't set up an account through the getting started wizard i instead set up a mail account manually but i guess i probably did something wrong... so running through the "getting started" and setting up the mail account allowed my script to work.. doh.

As a noob to php scripting i have a ton of questions:

why doesn't my mail() work? i get a fail with a pretty basic script...

when i run mail() it fails and yet i'm doing nothing fundamentally different than mrnutt and the tutorial example that is linked by vv.bbc19...

Code:
<?php

// mail example (doesn't work - no mail server???)

$to = "???????@tmrsoft.x10.bz";
$subject = "Test Mail";
$message = "Hello! This is a simple test email!";
$from = "???????@tmrsoft.x10.bz";
$headers = "From: $from Content-type: text/plain";
if(!mail($to, "Subject: $subject", $message, $headers))
	echo "mail error<br/>";
else
	echo "mail sent<br/>";

?>

i'm sending an email to myself, i gave up on sending to my gmail account.

i just added the Content-type: text/plain line because someone said that would make it work - but again no dice.

I suspect that i can't access the mail server unless i'm making an obvious error in my code that I can't see. So, is there anythiing i need to do to make this work, i've wasted days on this. I assumed that everything is configured properly but obviously i'm wrong, any help would be greatly appreciated.
 
Top