Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Mail

Pb Link <form> variables in index.html with mail.php ?

the mail() function

Moderators: macek, egami, gesf

Pb Link <form> variables in index.html with mail.php ?

Postby totoleheros » Fri Mar 30, 2012 12:23 am

Hello,

I have been struggling for the past 2 days with connecting my mail.php file with the web form variables located in index.html. I am able to send email via the gmail SMTP (I installed PHPMailer) however I am unable to to see the parameters the user entered when he filled out the form (his name, and some text, so 2 fields) when I receive the email sent by php via gmail smtp. :help:

-->Below is the html file

<form action="mail.php" method="POST">
<table align="center"><tr>
<td align="center" style="font-family:Helvetica;font-size:32px;font-weight: 300">Name:</td>
<td><input type="text" name="name" size=50></td>
<tr>
<td></td>
<td></td>
</tr>
</tr>

<tr>
<td align="center" style="font-family:Helvetica;font-size:32px;font-weight: 300">Text:</td>
<td><input type="text" name="content" size=50><td>
</tr>

<tr>
<td align="center"></td>

<td><input class="rounded" type="submit" value="Request Invitation" style="font-family:Helvetica;font-size:32px;font-weight: 300"></td>
</tr>

</table>
</form>

-->here is the mail.php.

<html>
<head><title>PHP Mail Sender</title></head>
<body>

<?php

require("./PHPMailer/class.phpmailer.php"); // path to the PHPMailer class

$mail = new PHPMailer();

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Mailer = "smtp";
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465;
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "@.com"; // SMTP username
$mail->Password = " "; // SMTP password

$mail->From = "";
$mail->AddAddress(" ");

$mail->Subject = "Invitation Request";
$mail->Body = "Hello";
$mail->WordWrap = 50;
$mail->Name = 'name'; // parameter used in index.html HOW TO CREATE THE LINK BETWEEN THE TWO FILES?
$mail->Content = 'content' ; // parameter used in index.html HOW TO CREATE THE LINK BETWEEN THE TWO FILES?
include 'index.html';// trying to create a link for the two above vaiables in index.html

(!$mail->Send()) {
echo 'Invitation request was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Invitation sent.';
}

?>

</body>
</html>

Many thanks !

D
totoleheros
New php-forum User
New php-forum User
 
Posts: 14
Joined: Fri Mar 30, 2012 12:09 am

Re: Pb Link <form> variables in index.html with mail.php ?

Postby freshnet » Fri Mar 30, 2012 12:40 am

Since you're posting to the mail page, you should be able to use something like

Code: Select all
$name = $_POST['name'];
$mail->Name = $name;
User avatar
freshnet
php-forum Active User
php-forum Active User
 
Posts: 252
Joined: Tue Feb 22, 2011 8:19 am
Location: Canada

Re: Pb Link <form> variables in index.html with mail.php ?

Postby totoleheros » Fri Mar 30, 2012 12:45 am

Hello freshnet,

Do you mean replacing the line $mail->Name = 'name' in the mail. php with
$name = $_POST['name'];
$mail->Name = $name;
?

Many thanks!

freshnet wrote:Since you're posting to the mail page, you should be able to use something like

Code: Select all
$name = $_POST['name'];
$mail->Name = $name;
totoleheros
New php-forum User
New php-forum User
 
Posts: 14
Joined: Fri Mar 30, 2012 12:09 am

Re: Pb Link <form> variables in index.html with mail.php ?

Postby freshnet » Fri Mar 30, 2012 12:56 am

yes that's correct!
User avatar
freshnet
php-forum Active User
php-forum Active User
 
Posts: 252
Joined: Tue Feb 22, 2011 8:19 am
Location: Canada

Re: Pb Link <form> variables in index.html with mail.php ?

Postby totoleheros » Fri Mar 30, 2012 1:04 am

Alright, I just did it and getting the following error message:

"Parse error: syntax error, unexpected '{' in ./mail.php on line 28"

which corresponds to the line: (!$mail->Send()) {


freshnet wrote:yes that's correct!
totoleheros
New php-forum User
New php-forum User
 
Posts: 14
Joined: Fri Mar 30, 2012 12:09 am

Re: Pb Link <form> variables in index.html with mail.php ?

Postby rupali » Fri Mar 30, 2012 1:24 am

hello,

you have missed if statement in the beginning, please check it once
it should be like this as
if(!$mail->Send())
{
// php code
}
rupali
New php-forum User
New php-forum User
 
Posts: 140
Joined: Thu Oct 13, 2011 10:32 pm
Location: Chandigarh, INDIA

Re: Pb Link <form> variables in index.html with mail.php ?

Postby totoleheros » Fri Mar 30, 2012 2:06 am

Hello Rupali, Hello Freshnet,

The email was successfully sent; which is good news. However, in the body of the email received, I still do not see the "name" and "content" variables entered by the user from the index.html.
I only see "Hello" in the subject field which corresponds to $mail->Body = "Hello"; in the mail.php file

Any idea? :oops:

Cheers,
Last edited by totoleheros on Fri Mar 30, 2012 2:46 am, edited 1 time in total.
totoleheros
New php-forum User
New php-forum User
 
Posts: 14
Joined: Fri Mar 30, 2012 12:09 am

Re: Pb Link <form> variables in index.html with mail.php ?

Postby totoleheros » Fri Mar 30, 2012 2:36 am

Eureka!
I replaced the former $mail->Body with $mail->Body = $_POST["content" ]; and received the content of the message in the body of the email received.

So to finish then, how can I enter multiple variable $mail->Body = $_POST["content" "name"] or $mail->Body = $_POST["content"; "name"] to show in the body?

Many Thanks again, I learnt a lot today
Toto
totoleheros
New php-forum User
New php-forum User
 
Posts: 14
Joined: Fri Mar 30, 2012 12:09 am

Re: Pb Link <form> variables in index.html with mail.php ?

Postby freshnet » Fri Mar 30, 2012 3:28 am

You should convert them each to variables... using a $_POST directly in your code isn't a good idea as it leaves you open to hacking.

Code: Select all
$name = $_POST['name'];
$content = $_POST['content'];
$mail->Body = $name . " " . $content; //depending on how you want to arrange it.
User avatar
freshnet
php-forum Active User
php-forum Active User
 
Posts: 252
Joined: Tue Feb 22, 2011 8:19 am
Location: Canada

Re: Pb Link <form> variables in index.html with mail.php ?

Postby totoleheros » Fri Mar 30, 2012 3:55 am

Dear freshnet,

when I write $mail->Body = $name . " " . $content; then the body is blank when I receive the email.
I am not sure what you mean with "You should convert them each to variables"; i am still in the learning process :oops:

freshnet wrote:You should convert them each to variables... using a $_POST directly in your code isn't a good idea as it leaves you open to hacking.

Code: Select all
$name = $_POST['name'];
$content = $_POST['content'];
$mail->Body = $name . " " . $content; //depending on how you want to arrange it.
totoleheros
New php-forum User
New php-forum User
 
Posts: 14
Joined: Fri Mar 30, 2012 12:09 am

Re: Pb Link <form> variables in index.html with mail.php ?

Postby freshnet » Fri Mar 30, 2012 4:36 pm

Ok try this then. It's better to not use $_POST variables directly for anything because they are more open to hacking. I could create any page that posts to your page and post my own variables in it.

Code: Select all
$name = $_POST['name'];
$content = $_POST['content'];
$mail->Body = $name;
$mail->Body .= $content;
User avatar
freshnet
php-forum Active User
php-forum Active User
 
Posts: 252
Joined: Tue Feb 22, 2011 8:19 am
Location: Canada

Re: Pb Link <form> variables in index.html with mail.php ?

Postby rupali » Fri Mar 30, 2012 10:14 pm

Hello Toto,

Please Check the attachment
Hope it works !!!
Attachments
phpmailer.rar
(23.96 KiB) Downloaded 43 times
rupali
New php-forum User
New php-forum User
 
Posts: 140
Joined: Thu Oct 13, 2011 10:32 pm
Location: Chandigarh, INDIA

Re: Pb Link <form> variables in index.html with mail.php ?

Postby totoleheros » Sat Mar 31, 2012 6:44 am

Hello Rupali,

Many thanks. This is great!! Cheers

rupali wrote:Hello Toto,

Please Check the attachment
Hope it works !!!
totoleheros
New php-forum User
New php-forum User
 
Posts: 14
Joined: Fri Mar 30, 2012 12:09 am

Re: Pb Link <form> variables in index.html with mail.php ?

Postby rupali » Sat Mar 31, 2012 5:55 pm

Hello Toto,

my pleasure !!! :)
Have a superb weekend !!!
rupali
New php-forum User
New php-forum User
 
Posts: 140
Joined: Thu Oct 13, 2011 10:32 pm
Location: Chandigarh, INDIA

Re: Pb Link <form> variables in index.html with mail.php ?

Postby ladygaga627 » Mon May 21, 2012 1:33 am

Just want to say you are great...like this topic so much...learning more ine here.
________________
Like shopping when i have a good time.
Rs Gold|Runescape gold|Cheap Runescape gold
ladygaga627
New php-forum User
New php-forum User
 
Posts: 1
Joined: Mon May 21, 2012 1:26 am

Re: Pb Link <form> variables in index.html with mail.php ?

Postby rupali » Fri May 25, 2012 5:14 pm

Thanks ladygaga627 :)

Have a nice Weekend !!!
rupali
New php-forum User
New php-forum User
 
Posts: 140
Joined: Thu Oct 13, 2011 10:32 pm
Location: Chandigarh, INDIA


Return to PHP coding => Mail

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.