|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
I've to implement a php script in a web page to send mail.
If I use a .html form and a separate .php script, all works fine. In the contrary, if I try to put the script into the .html file, I've some troubles... Here's the code: ================================================== ==================== <?php ?> <xml version="1.0" encoding="utf-8"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="generator" content="Quanta Plus" > <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>B#038;B #171;LA LOCANDA DI RE MANFREDI#187; - PALAZZO SAN GERVASIO (PZ)</title> <meta name="description" content="Ora c'#232; un Bed#038;Breakfast anche a Palazzo San Gervasio (PZ)" > <meta name="keywords" content="b#038;b,bed#038;breakfast, Palazzo San Gervasio, Potenza, Basilicata, Lucania" > <link rel="stylesheet" type="text/css" href="layout.css" > </head> <body> <ul class="navbar"> <li><a href="index.html">Home Page</a></li> <li><a href="bed.html">Il nostro Bed#038;Breakfast</a></li> <li><a href="paese.html">Il paese</a></li> <li><a href="storia.html">La storia</a></li> <li><a href="tradizioni.html">Le tradizioni</a></li> <li><a href="indirizzi.html">Indirizzi utili</a></li> </ul> <h2>#200; possibile inviarci una comunicazione direttamente da questo form</h1> <h2>Riempire i campi richiesti e premere il pulsante "Invia"</h2> <br /><br /> <? if (isset($_POST['action']) && ($_POST['action']=='invia')) { $receiverMail = "samiel@netsons.org"; $name = ltrim(rtrim(strip_tags(stripslashes($_POST['name'])))); $email = ltrim(rtrim(strip_tags(stripslashes($_POST['email'])))); $subject = ltrim(rtrim(strip_tags(stripslashes($_POST['subject'])))); $msg = ltrim(rtrim(strip_tags($_POST['msg']))); $ip = getenv("REMOTE_ADDR"); $msgformat = "Messaggio da: $name ($ip)\nEmail: $email\n\n$msg"; if(empty($name) || empty($email) || empty($subject) || empty($msg)) { echo "<h3>Il messaggio non e' stato inviato</h3> <h3>Si prega di compilare tutti i campi</h3"; ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> Nome:<br ><br > <input name="name" size="50" maxlength="40" > <br ><br/><br > Indirizzo e-mail:<br /><br /> <input name="email" size="50" maxlength="40" > <br ><br ><br > Oggetto:<br ><br > <input name="subject" size="50" maxlength="40" > <br ><br ><br > Messaggio:<br ><br > <textarea name="msg" cols="50" rows="8"></textarea> <br ><br ><br > <input type="submit" value="Invia" > #160; #160; #160; #160; #160; #160; <input type="reset" value="Cancella" > </form> <? } elseif(!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z {2,3})$", $email)) { echo "<h3>Il messaggio non e' stato inviato</h3> <h3>L'indirizzo e-mail indicato non e' valido</h3>"; ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> Nome:<br /><br /> <input name="name" size="50" maxlength="40" value=?> echo $name. <?"> <br /><br /><br /> Indirizzo e-mail:<br /><br /> <input name="email" size="50" maxlength="40" value="wrong!" > <br /><br /><br /> Oggetto:<br /><br /> <input name="subject" size="50" maxlength="40" value="?>echo $subject;<?> <br /><br /><br /> Messaggio:<br /><br /> <textarea name="msg" cols="50" rows="8">?> echo $message;<?</textarea> <br /><br /><br /> <input type="submit" value="Invia" >> #160; #160; #160; #160; #160; #160; <input type="reset" value="Cancella" > </form> <? } else { mail($receiverMail, $subject, $msgformat, "From: $name <$email>"); echo "<h3>Il messaggio e' stato inviato correttamente<h3> <h3>Risponderemo il piu' presto possibile</h3> <h3>Grazie di averci scritto</h3>"; } } ?> </body> </html> ================================================== ==================== When I try to open the page, I receive this error: Parse error: syntax error, unexpected T_STRING in /var/www/netsons.org/samiel/form2.php on line 79 Do u see my error? Thanx! MS -- linux user no.: 353546 public key at http://keyserver.linux.it |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
Mauro Sacchetto wrote:
> I've to implement a php script in a web page to send mail. > If I use a .html form and a separate .php script, all works fine. > In the contrary, if I try to put the script into the .html file, > I've some troubles... Here's the code: > > ... > > When I try to open the page, I receive this error: > > Parse error: syntax error, unexpected T_STRING > in /var/www/netsons.org/samiel/form2.php on line 79 > > Do u see my error? {Copies, pastes into editor that will number the lines ...} Well, looking in the vicinity of line 79, i'd say the problem lies with your reversed PHP tags: <input name="name" size="50" maxlength="40" value=?> echo $name. <?"> You've got another right below that: <input name="subject" size="50" maxlength="40" value="?>echo $subject;<?> And another: <textarea name="msg" cols="50" rows="8">?> echo $message;<?</textarea> Some other points: - You can do without the "echo" by using, eg. <?= $message ?> - Because this is an XHTML page, you should be closing your input tags and properly quoting the attributes: value="<?= $name ?>" /> - That your script's purpose is to send mail has nothing to do with how it displays in a browser. Anyway, that should do it. Be sure to validate the page. brian |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
brian wrote:
> Mauro Sacchetto wrote: >> I've to implement a php script in a web page to send mail. >> If I use a .html form and a separate .php script, all works fine. >> In the contrary, if I try to put the script into the .html file, >> I've some troubles... Here's the code: >> >> ... >> >> When I try to open the page, I receive this error: >> >> Parse error: syntax error, unexpected T_STRING in >> /var/www/netsons.org/samiel/form2.php on line 79 >> >> Do u see my error? > > {Copies, pastes into editor that will number the lines ...} > > Well, looking in the vicinity of line 79, i'd say the problem lies with > your reversed PHP tags: > > <input name="name" size="50" maxlength="40" value=?> echo $name. <?"> > > You've got another right below that: > > <input name="subject" size="50" maxlength="40" value="?>echo $subject;<?> > > And another: > > <textarea name="msg" cols="50" rows="8">?> echo $message;<?</textarea> > > Some other points: > > - You can do without the "echo" by using, eg. <?= $message ?> Yet later in another thread you complain about short_tags being an option.. can't have it both ways. Leave it as <?php echo $message; ?> it's more portable - it will work on every single php server and you won't have any issues moving your code around. -- Postgresql & php tutorials http://www.designmagick.com/ |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
Chris wrote:
> brian wrote: >> >> - You can do without the "echo" by using, eg. <?= $message ?> > > > Yet later in another thread you complain about short_tags being an > option.. can't have it both ways. Oh, is that so? Let's see what i wrote ... -- snip -- .... Better yet, PHP should do away with <? ?> altogether but allow <?= ?>, which is *very* ful (to those of us who choose to use it). -- snip -- > Leave it as <?php echo $message; ?> > > it's more portable - it will work on every single php server and you > won't have any issues moving your code around. > -- snip -- I do agree that developing with short_open_tags = on is a Bad Idea if the app will not be under one's control. -- snip -- But thanks. I know you were really trying. brian |
|
![]() |
| Outils de la discussion | |
|
|