0
votes

Hi Im creating a form in which i enter the user details and provide them user name and password through email for login purpose.

Problem: Using post method i would like to send email to the user. But it shows the email sent but email not yet received.

If to address is directly given email is sent. $to:[email protected] - mail is sent.

Im sending email in localhost using Send mail.

My form is

<form name="assignteacher" method="post" action="../path.php">

<table align="center" width="450px">

<tr>

<td valign="top">

<label for="teacherid">Teacher ID</label>

</td>

<td valign="top">

<input  type="text" name="teacherid" maxlength="50" size="30">

</td>

</tr>
<tr>

<td valign="top">

<label for="email">Email</label>

</td>

<td valign="top">

<input  type="email" name="email" maxlength="50" size="30">

</td>

</tr>
<tr>

<td valign="top">

<label for="username">User Name</label>

</td>

<td valign="top">

<input  type="text" name="username" maxlength="50" size="30">

</td>

</tr>

<tr>

<td valign="top"">

<label for="password">Password</label>

</td>

<td valign="top">

<input  type="text" name="password" maxlength="50" size="30">

</td>

</tr>

<tr>

<td valign="top">

<label for="class">Class Assigned</label>

</td>

<td valign="top">

<input  type="text" name="class" maxlength="80" size="30">

</td>

</tr>



<tr>

<td colspan="2" style="text-align:center">

<input type="submit" value="Submit">   
<a href="http://www.freecontactform.com/email_form.php">Email Form</a>

</td>

</tr>

</table>

</form>

My PHP Code is..

<?php

$emailid=$_POST['email'];
$to='$emailid';
$subject='Your Login info';

$message ="username: ".$_POST['username']."\r\n"; 
$message .= "Password: ".$_POST["password"]."\r\n"; 
  $message .= "class: ".$_POST["class"]."\r\n";  



$headers="from:[email protected]" . "\r\n" .
        "Reply_to:[email protected]" . "/r/n" .
        "MIME-version:1.0" . "\r\n" .
        "Content-type:text/html" . "\r\n" .
        "X-Mailer:PHP/" . phpversion();
if(mail($to, $subject, $message, $headers))
echo "mail sent";
else
echo"mail sending failed";




?>

Kindly help me in this. bear with me if i made any spell or grammar mistakes.

4
If the mail function returns true then the mail was sent as far as PHP is aware. If you're not receiving it (check spam folders too...) then it's either not leaving your machine or being rejected by google servers. Make sure your server is set with the proper reverse dns and typical anti-spam configurationhelion3

4 Answers

0
votes

No need for giving single quotes to $to='$emailid'; as it is a PHP varible containing string value. Give as below:

$to=$emailid;
0
votes

If you are using Xampp, you have to modify 2 ini files: php.ini and sendmail.ini 1)look for mail function in php.ini(c:/xampp/php/php.ini)>>[mail function] change the following:

SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = [email protected]
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

2) next modify sendmail.ini(c:/xampp/sendmail/sendmail.ini) Edit the following lines (or copy and paste if you don't have them then edit it)

account Gmail
tls on
tls_certcheck off
host smtp.gmail.com
from [email protected]
auth on
user [email protected]
password x

port 587

account default : Gmail

Save both of these files then test it with this code

<?php
$subject="Test mail";
$to="[email protected]";
$body="This is a test mail";
if (mail($to,$subject,$body)) {
echo "Mail sent successfully!";
} else {
echo"Mail not sent!";
}
?>
-1
votes

You are using HTML 5 attribute for input, It will work only on modern browsers.. So do changes as follows

in HTML

<input  type="text" name="email" maxlength="50" size="30">

in PHP fix error

$to=$emailid;
-1
votes

The second line $to='$emailid'; should be $to=$emailid;

It's worth pointing out that this is a massive security risk - this code shouldn't be available on the public Internet, unless it's password protected.