Nov 24, 2009

Php Mail Function Not Working! - I can't get the mail function work and I can't figure out why.

free web hosting
Open Discussion > MODERATED AREA > The Internet > Web Design

Php Mail Function Not Working! - I can't get the mail function work and I can't figure out why.

baniboy
Well in this month when I started transforming my unready xhtml files into php and making mail function by POST since I figured out "GET" is an insecure way of transforming information of other people. I got problem, it's in finnish but I have explained the stuff in English in the comment lines. And one more thing, I'm newbie so don't laugh too much if there is somehitng wrong with the simplest thing, please!

Here's the form:
HTML
<form action="skriptit/sivupalauteskripti.php" method="post">
<b>Nimi:</b> <br> <input type="text" name="nimi"> <br> <!-- This is the name input text area -->
<b>Sähköposti:</b> <br> <input type="text" name="sposti"> <br> <!-- This is e-mail input -->
<b>Palaute:</b> <br><textarea name="palaute"> <!-- Another text area for comments -->
</textarea> <br>
<input type="submit" value="Lähetä palaute"> <!-- The submit button -->
</form>


And the php script:
CODE
<?php

//I don't know how to explain this on English, you should get what this does after a few looks :D "nimi" is the name and "arvo" is value, I think something is wrong with them but I don't know what!

foreach($_POST as $nimi => $arvo) {
   $palaute .= $nimi . ": " . $arvo . "\n";
}

//Send the comment to email by php "mail" function
$viesti = mail("my-email@myemail.com", "Palaute", $palaute);

//$viesti is true when email is sent succesfully
if($viesti) {
   //when sent succesfully, it redirects to the thank you page
   header("Location: ../kiitos.php");
} else {
   //If not, it will redirect to the error page
   header("Location: ../virhe.php");
}
?>

Edit: I would also like to know if I can do this in another way without the spam bots picking out my e-mail address
Notice from truefusion:
Use code bbcode, or others, for code.

 

 

 


Comment/Reply (w/o sign-up)

xpress
You hadn't mentioned what problem you are getting. But I am assuming that you can't connect or send mails on localhost using your program. So I am correcting your mistakes as per my assumption.

First of all I would like to tell you some simple basic things in this. You must have a mail server installed and the service should run in the background if you want to send mails to your localhost. If not it will give you an error that "Failed to connect localhost...."

Your mail program and some names you used are quiet confusing for me.... sorry, I am changing them for my convenience...
here is an easy version for your program. I'll point out the mistakes at that particular part of the code.

This is your form....lets name it mailform.html

CODE
<form action="mymail.php" method="post">
Enter your Name:<input type="text" name="name" /> <br />
Enter your Email:<input type="text" name="email" /> <br />
Enter your Message:<textarea name="message"> Enter your message here</textarea><br />
<input type="submit" value="Submit" />
</form>


Now the php program that handles your code...lets name it processmail.php(as in form).
I changed this program also to make it clear and easy to understand.

CODE
<?php

//you can use your foreach here but that is confusing

$name=$_POST['name'];              //this will receive the name
$email=$_POST['email'];            //this will receive the email address you mentioned
$message=$_POST['message'];        //receives the textarea

$recipent="yourname@yourdomain.com";   //you should set this in your local smtp server...this is to in mail function
$subject="user details form";          //this is subject

//This is the main mistake you made I think...you must have From header in your mail funcion or you should set it in php.ini file.

$header="From:$name";                     //From header is must
$header .= "Reply-To:$email";             //jsut adding headers

$send=mail($recipent, $subject, $message, $header) or die("failure");  //recipent, subject and message are must

if($send)
echo "success";
?>


I write this code as per my assumption of your mistake. Modify this code but follow the mail functions syntax....

First download a mail server like hMailServer(I'm using this...nice one) or someother else. And add a domain like mydomain.some and create a new mail account in that.....use that as your recipent address.

If your problem is different or if you can't understand this...post your problem(or error you are getting) clearly here and I'll try to solve your problem smile.gif

 

 

 


Comment/Reply (w/o sign-up)

baniboy
Thankyou xpress, you know what I do: screw everything up with something too confusing even I don't undrestand myself. I'll try a web server and create an account on there. I'll tell if it worked out fine. Thanks for the help

Comment/Reply (w/o sign-up)

xpress
QUOTE(baniboy @ Dec 1 2008, 10:09 PM) *
I'll try a web server and create an account on there. I'll tell if it worked out fine. Thanks for the help


You're welcome smile.gif You'll Try a webserver or mail server? Setup a mail server...(I think you already have a webserver installed)

Comment/Reply (w/o sign-up)

baniboy
QUOTE
You're welcome. You'll Try a webserver or mail server? Setup a mail server...(I think you already have a webserver installed)

Not actually, which web server you suggest?

For now I've just moved my php files on the net and tried them out.

Comment/Reply (w/o sign-up)

xpress
For PHP......use WAMP server. It has Apache Webserver, MySql and PHP included. So no need to install all of them separately. I have been using it for some time. It is easy to install and manage. Another one is XAMPP.....but I suggest WAMP server. Download and install it. Ask me if you need any assistance setting up it...

Comment/Reply (w/o sign-up)

baniboy
I wonder if there is a way to get the forms directly to your normal email account, like the one in msn or yahoo or gmail etc. It would be quite handy, don't you think?

Comment/Reply (w/o sign-up)

xpress
I didn't understand what you said. Do you mean sending mails directly from your mail account or to your mail account?

Comment/Reply (w/o sign-up)

baniboy
QUOTE (xpress @ Dec 3 2008, 04:11 PM) *

I didn't understand what you said. Do you mean sending mails directly from your mail account or to your mail account?


I ment like if you have a e-mail account provided my popular service like yahoo, let's name it "myemail@yahoo.com" then with alittle programming you would have the form to be sent to your myemail@yahoo.com

Comment/Reply (w/o sign-up)

veerumits
Dear i am here posting the information regarding sending mail from mail server to any client using php tools

CODE
<?php
if(isset($_REQUEST['Submit']))
{
        @extract($_POST);
      
            $subject=$subject;
          
$msg="Name:".$name."\n"."Email:".$email."\n"."Message:".$msg;
$to="yourmail@yahoo.com";        
$headers .= "Reply-to: $headers4\n";
$headers .= "From: $email\n";
$headers .= "Errors-to: $headers4\n";
    if(mail("$em","Query!!!","$msg \n \n Site Admin","$headers"))
  
    {
  
    $massage1="<center><font face='Verdana' size='2' ><b>THANK YOU</b> <br>Your email has been sent successfully..</center>";
    }
    else{
  
    echo " <center><font face='Verdana' size='2' color=red >There is some system problem in sending login details to your address. Please contact Site Admin. <br></center></font>";
  
    }
}      

?>
<table width="99%" border="0" align="center" cellpadding="0" cellspacing="5" bgcolor="#CCCCFF">
              <form method="post" action="Contactus.php" enctype="multipart/form-data" name="form" >
              <tr>
                <td width="27%" align="right" class="form_text">Name<span class="price_text">*</span> </td>
                <td width="73%" align="left"><input name="name" type="text" class="form_text_area" id="name" maxlength="32" /></td>
              </tr>
              <tr>
                <td align="right" class="form_text">Email<span class="price_text">*</span> </td>
                <td align="left"><input name="email" type="text" class="form_text_area" id="email" maxlength="32" /></td>
              </tr>
              <tr>
                <td align="right" class="form_text">Subject<span class="price_text"> *</span></td>
                <td align="left"><input name="subject" type="text" class="form_text_area" id="subject" maxlength="32" />                </td>
              </tr>
              <tr>
                <td align="right" class="form_text">Message<span class="price_text"> *</span></td>
                <td align="left"><label>
                  <textarea name="msg" cols="30" rows="10" id="msg"></textarea>
                </label></td>
              </tr>
              <tr>
                <td align="right" class="form_text">&nbsp;</td>
                <td align="left"><label>
                  <input type="submit" name="Submit" value="Submit" />
                </label></td>
              </tr>
</form></table>


if still have any question in this topic please reply.

thanks



QUOTE (baniboy @ Dec 4 2008, 12:39 AM) *



I ment like if you have a e-mail account provided my popular service like yahoo, let's name it "myemail@yahoo.com" then with alittle programming you would have the form to be sent to your myemail@yahoo.com



Comment/Reply (w/o sign-up)



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : php, mail, function, working, mail, function, work, figure,

  1. Disabling Right Click Function
    (12)
  2. 30 Gb Mail Account For Free On Internet
    (19)
    In Order To Get 30Gb Mail Account Simply Click The Links Given Below And Register On The That
    Website For 30GB Mail Account.. Click Here: http://www.congloi.5gigs.com/30gigs/ Mirror Or Same
    Thing With Different Link: http://www.30gigs.com/accept/140083/ebdde3...941de344441d08c Well If U
    Like My This Inventory Please Rate It Also Do Tell Me Your Thoughts About This Thanx......
  3. Form Mail (in Csv Or Straight Html)
    All suggestions are welcome (0)
    I have been searching for scripts to write to do the followings: 1) validate that an applicant has
    all required field checked (this is to thin out who is serious and who's just browsing)--DONE 2)
    application page (applicant fills in all form fields)--DONE 3) mail the entire page content either
    in CSV or as is in HTML as attachment via email through web 4) "optional" confirmation page I was
    led to this site (http://www.email-form.com/) for a program called Form Processor Pro. This program
    will take care of the step 3 and 4 without saving to the server. My question....
  4. Website Building- E-mail Forwarding & Downloads
    Response Forms & downloading zip files (9)
    Hi guys, Am new to designing. How do I : 1) include a popup form on my webpage for the visitor to
    input info & have the info forwarded to my personal e-mail account (not trap17). 2) make links to
    download files (ie. zip etc.) hosted on my website for ftp direct download to the visitors computer.
    (You know, click a link & the file automatically downloads) Any info appreciated !!! Tutorials
    ????????????????? Step by step info ???????????? Thanks in advance RGPHNX....

    1. Looking for php, mail, function, working, mail, function, work, figure,

Searching Video's for php, mail, function, working, mail, function, work, figure,
See Also,
advertisement


Php Mail Function Not Working! - I can't get the mail function work and I can't figure out why.

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com