PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.general > Php script for mail in a xhtml page
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Php script for mail in a xhtml page

Réponse
 
LinkBack Outils de la discussion
Vieux 08/09/2007, 01h56   #1 (permalink)
Mauro Sacchetto
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Php script for mail in a xhtml page

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
  Réponse avec citation
Vieux 08/09/2007, 02h24   #2 (permalink)
brian
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Php script for mail in a xhtml page

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
  Réponse avec citation
Vieux 10/09/2007, 03h37   #3 (permalink)
Chris
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Php script for mail in a xhtml page

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/
  Réponse avec citation
Vieux 10/09/2007, 15h08   #4 (permalink)
brian
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Php script for mail in a xhtml page

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
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 03h06.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,13003 seconds with 12 queries