Jump to content

Mail not sending

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
7 replies to this topic

#1
njr1489

njr1489

    Learning Programmer

  • Members
  • PipPipPip
  • 70 posts
So far, i've read tutorials which have said to create a form with an action and method attribute like so:

<form action="sendmail.php" method="post">

<table>

<tr><td><label>Name:</label></td><td><input type="text" name="txtboxname" /></td></tr>

<tr><td><label>Email: </label></td><td><input type="text" name="txtboxemail" /></td></tr>

<tr><td><label>Subject: </label></td><td><input type="text" name="txtboxsubject" /></td></tr>

</table>

<textarea rows="7" cols="22" id="txtmessage"></textarea>


<input type="button" id="btnsend" value="Send" />

</form>

Then I used a php script called sendmail.php located elsewhere, here is the code:

<?php

$to = "noeljramos@gmail.com";

$subject = "Message email from website " . $_REQUEST['txtboxsubject'];

$message = $_REQUEST['txtmessage'];

$headers = $_REQUEST['txtboxemail'];

if (mail($to, $subject, $message, $headers))

	echo "IT WORKS";

else

	echo "DIDNT WORK";

?>

This does not send me anything, would anyone care to tell me why?

#2
BlaineSch

BlaineSch

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,448 posts
Does this return "IT WORKS" or "DIDNT WORK"?

You might have mail disabled in the php.ini file. You may want to check that file.

#3
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Or your server isn't setup properly. If you are on a Windows server, you'll need to setup an SMTP server via your php.ini file.

#4
njr1489

njr1489

    Learning Programmer

  • Members
  • PipPipPip
  • 70 posts
I just learned PHP yesterday, so I haven't heard of the PHP.ini file before. I think that might be it. Any tips on getting/creating one? I'm not sure whether or not there is an existing ini file on the server.

#5
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Are you on Windows or a Linux box? Also, how did you install PHP if on Windows OR what distribution of Linux are you using?

#6
njr1489

njr1489

    Learning Programmer

  • Members
  • PipPipPip
  • 70 posts
It's being run on Debian Linux, if I'm mistaken, there is no installation required if running on Linux?\

UPDATE: Ok so I checked and there is a PHP.ini file setup. Interestingly enough, if I go to sendmail.php on my browser, it will send me a blank email since there is no information to request. At least I know it can send me mail, I just need to configure it to send me the mail with the information on the textboxes.

Edited by njr1489, 03 November 2009 - 06:29 PM.


#7
njr1489

njr1489

    Learning Programmer

  • Members
  • PipPipPip
  • 70 posts
I've fixed it myself. It was a pretty noobish mistake on my part. My attribute on the input for a button shouldn't be button, it's supposed to be submit! Everything else was fine, here is the fix.

<input type="button" id="btnsend" value="Send" />


I can't believe this one small mistake made me run in circles for 3 days.:D

#8
joe2010

joe2010

    Newbie

  • Members
  • PipPip
  • 10 posts
next time try the code with out the form. make a secret page sdofj.php and in that have hard coded values for the subject, from, to etc

this can be applied to any problem when trying to test the logic only - saved me a lot of time. and if your working on windows then you can get XAMPP or other package to develop test on local quicker (it comes with php, mysql, perl) etc is a great help