Eroare la un formular cu PHP

Discutii despre script-uri si coduri PHP-MySQL, precum si lucru cu XML in PHP.
marius91stefan
Mesaje: 5

Eroare la un formular cu PHP

Salut. Am si eu o problema. In primul rand nu stiu daca am postat unde trebuie si am cautat pe forum ceva asemanator cu problema mea insa nu am gasit.
Am asta intr-un HTML:

Cod: Selectaţi tot

<form name="NUME" method="post" action="NUME.php">
<p><strong><font color="#b90c31">Section 1</strong> - Personal Informations</font><br />
By default, sendings this form you are agree with GDPR.</p>
<label>Full name:</label>
<input type="text" size="15" maxlength="45" name="fullname" /> 
<label>E-mail:</label>
<input type="email" size="18" id="email" name="email">
<label>Your website:</label>
<input type="text" size="25" maxlength="45" name="yourwebsite" />
<label>Phone:</label>
<input type="text" size="13" maxlength="16" name="phone" /><br />
<label>We reach you:</label>
<select name="wereachyou"> 
  <option>via phone</option> 
  <option>via e-mail</option> 
</select>
<p><strong><font color="#b90c31">Section 3</strong> - Validate your informations</font><br />
Please reconfirm the next informations.</p>
<label>E-mail confirmation:</label>
<input type="email" size="18" id="reconfirmemail" name="reconfirmemail">
<label>Your website confirmation:</label>
<input type="text" size="25" maxlength="45" name="reconfirmyourwebsite" />
<label>Phone confirmation:</label>
<input type="text" size="13" maxlength="16" name="reconfirmphone" />
<p></p>
<input type="submit" value="   Request a personal offer   " />
</form>
si am acest php:

Cod: Selectaţi tot

<?php
// Verifica daca au fost trimise datele de la formular
if (isset($_POST['email']) && isset($_POST['phone'])) {
    $to = 'contact@hefferec.ro';                 // Adresa unde va fi trimis mesajul
    $subiect = 'Achizitionare  - Client: $_POST['fullname']';
    $mesaj = <strong><font color="#b90c31">Raspunsurile au fost astfel:</font><br />Sectiunea 1 - Personal Informations</strong><br />Full name: $_POST['fullname']<br />Email: $_POST['email']<br />Your website: $_POST['yourwebsite']<br />Phone: $_POST['phone']<br />We reach you: $_POST['wereachyou']<br /><strong>Sectiunea 3 - Validate your informations</strong><br />E-mail confirmation: $_POST['reconfirmemail']<br />Your website confirmation: $_POST['reconfirmyourwebsite']<br />Phone confirmation: $_POST['reconfirmphone']<br />;
    $from = 'From: '. $_POST['email'];

    // PHP trimite datele la serverul de e-mail
    if (mail($to, $subiect, $mesaj, $from)) {
              echo 'We come back to you shortly ~ under 5 minutes.<br />Please check your email: <strong>Inbox</strong> or <strong>Spam/Bulk</strong> folder.';
    }
    else {
              echo 'Error occurred while sending email.<br />Please write a mail and send it to <strong>contact@hefferec.ro</strong>.';
    }
}
?>
Erorile pe care le primesc sunt urmatoarele:

Cod: Selectaţi tot

[31-Jan-2022 17:08:44 UTC] PHP Parse error:  syntax error, unexpected 'fullname' (T_STRING) in /home/wwwheffe/public_html/package.php on line 5
[31-Jan-2022 17:10:00 UTC] PHP Parse error:  syntax error, unexpected '<' in /home/wwwheffe/public_html/NUME.php on line 6
Nu inteleg ce nu este in regula. Am urmat pasii de aici (https://marplo.net/php-mysql/email.html) intocmai insa fiind la inceput cred ca pe undeva sigur am gresit si nu stiu unde.

MarPlo Mesaje: 4343
Salut,
E gresala in codul php. Nu se adauga variabiile de array sau ghilimele simple in interiorul unui sir incadrat cu ghilimele simple; se foloseste concatenarea.
Incearca urmatorul cod, si vezi deferenta.

Cod: Selectaţi tot

<?php
// Verifica daca au fost trimise datele de la formular
if (isset($_POST['email']) && isset($_POST['phone'])) {
    $to = 'contact@hefferec.ro';  // Adresa unde va fi trimis mesajul
    $subiect = 'Achizitionare  - Client: '. $_POST['fullname'];
    $mesaj = '<strong><font color="#b90c31">Raspunsurile au fost astfel:</font><br />Sectiunea 1 - Personal Informations</strong><br />Full name: '. $_POST['fullname'].'<br />Email: '. $_POST['email'].'<br />Your website: '.$_POST['yourwebsite'].'<br />Phone: '.$_POST['phone'].'<br />We reach you: '.$_POST['wereachyou'].'<br /><strong>Sectiunea 3 - Validate your informations</strong><br />E-mail confirmation: '.$_POST['reconfirmemail'].'<br />Your website confirmation: '.$_POST['reconfirmyourwebsite'].'<br />Phone confirmation: '.$_POST['reconfirmphone'].'<br />';
    $from = 'From: '. $_POST['email'];

    // PHP trimite datele la serverul de e-mail
    if (mail($to, $subiect, $mesaj, $from)) {
      echo 'We come back to you shortly ~ under 5 minutes.<br />Please check your email: <strong>Inbox</strong> or <strong>Spam/Bulk</strong> folder.';
    }
    else {
      echo 'Error occurred while sending email.<br />Please write a mail and send it to <strong>contact@hefferec.ro</strong>.';
    }
}
?>

marius91stefan Mesaje: 5
Am schimbat putin (in sensul ca am mai adaugat niste campuri si in php si in html) insa tot nu functioneaza. Acum primesc o alta eroare, folosind textul copiat de mai sus :(

Cod: Selectaţi tot

[01-Feb-2022 19:14:24 UTC] PHP Parse error:  syntax error, unexpected '';
' (T_CONSTANT_ENCAPSED_STRING) in /home/wwwheffe/public_html/NUME.php on line 6

Daca scot de la $mesaj ' (De la inceput si de la sfarsit) sau le inlocuiesc cu " eroarea se muta pe randul 8:


Codul php:

Cod: Selectaţi tot

<?php
// Verifica daca au fost trimise datele de la formular
if (isset($_POST['email']) && isset($_POST['phone'])) {
  $to = 'contact@hefferec.ro';                 // Adresa unde va fi trimis mesajul
  $subiect = 'Achizitionare GaMING package - Client: '. $_POST['fullname']';
  $mesaj = 	        '<strong><font color="#b90c31">Raspunsurile au fost astfel:</font>
    <br />Sectiunea 1 - Personal Informations</strong>
    <br />Full name: '. $_POST['fullname'].'
    <br />Email: '. $_POST['email'].'
    <br />Your website: '. $_POST['yourwebsite'].'
    <br />Phone: '. $_POST['phone'].'
    <br /><strong>Sectiunea 2 - Informations about your expectations</strong>
    <br />How many days do you have until now? '. $_POST['days'].'
    <br />You will be able to do step 3 without our help? '. $_POST['step3'].'
    <br />You will sending external signals to raise your account? '. $_POST['raisebusiness'].'
    <br />The evolution of the account will be further monitored by: '. $_POST['evolution'].'
    <br />How long do you intend to keep your account monitored? '. $_POST['keepaneye'].'
    <br />How many logins do you have per day? '. $_POST['visits'].'
    <br /><strong>Sectiunea 3 - Validate your informations</strong>
    <br />E-mail confirmation: '. $_POST['reconfirmemail'].'
    <br />Your website confirmation: '. $_POST['reconfirmyourwebsite'].'
    <br />Phone confirmation: '. $_POST['reconfirmphone'].'<br />';
  $from = 'From: '. $_POST['email'];

  // PHP trimite datele la serverul de e-mail
  if (mail($to, $subiect, $mesaj, $from)) {
    echo 'We come back to you shortly ~ under 5 minutes.<br />Please check your email: <strong>Inbox</strong> or <strong>Spam/Bulk</strong> folder.';
  }
  else {
    echo 'Error occurred while sending email.<br />Please write a mail and send it to <strong>seopackage@hefferec.ro</strong>.';
  }
}
?>

MarPlo Mesaje: 4343
Ai pus o ghilimea care nu era necesara la sfarsitul liniei 5, dupa variabila. Nu era nevoie fiindca nu mai era nici un sir de caractere, ci sfarsit de cod.

Cod: Selectaţi tot

<?php
// Verifica daca au fost trimise datele de la formular
if (isset($_POST['email']) && isset($_POST['phone'])) {
  $to = 'contact@hefferec.ro';                 // Adresa unde va fi trimis mesajul
  $subiect = 'Achizitionare GaMING package - Client: '. $_POST['fullname'];
  $mesaj = '<strong><font color="#b90c31">Raspunsurile au fost astfel:</font>
    <br />Sectiunea 1 - Personal Informations</strong>
    <br />Full name: '. $_POST['fullname'].'
    <br />Email: '. $_POST['email'].'
    <br />Your website: '. $_POST['yourwebsite'].'
    <br />Phone: '. $_POST['phone'].'
    <br /><strong>Sectiunea 2 - Informations about your expectations</strong>
    <br />How many days do you have until now? '. $_POST['days'].'
    <br />You will be able to do step 3 without our help? '. $_POST['step3'].'
    <br />You will sending external signals to raise your account? '. $_POST['raisebusiness'].'
    <br />The evolution of the account will be further monitored by: '. $_POST['evolution'].'
    <br />How long do you intend to keep your account monitored? '. $_POST['keepaneye'].'
    <br />How many logins do you have per day? '. $_POST['visits'].'
    <br /><strong>Sectiunea 3 - Validate your informations</strong>
    <br />E-mail confirmation: '. $_POST['reconfirmemail'].'
    <br />Your website confirmation: '. $_POST['reconfirmyourwebsite'].'
    <br />Phone confirmation: '. $_POST['reconfirmphone'].'<br />';
  $from = 'From: '. $_POST['email'];

  // PHP trimite datele la serverul de e-mail
  if (mail($to, $subiect, $mesaj, $from)) {
    echo 'We come back to you shortly ~ under 5 minutes.<br />Please check your email: <strong>Inbox</strong> or <strong>Spam/Bulk</strong> folder.';
  }
  else {
    echo 'Error occurred while sending email.<br />Please write a mail and send it to <strong>seopackage@hefferec.ro</strong>.';
  }
}
?>

marius91stefan Mesaje: 5
Codul php functioneaza acum, insa exista o eroare la codul html pentru ca primesc mesajul de eroare din php cel cu Error occured while ....

Cod: Selectaţi tot

<form name="contact" method="post" action="NUME.php">
											<p><strong><font color="#b90c31">Section 1</strong> - Personal Informations</font><br />
											By default, sendings this form you are agree with GDPR.</p>
												Full name: <input type="text" size="30" name="fullname"/>
												<br />
												E-mail: <input type="email" size="33" name="email"/>
												<br />
												Your website: <input type="text" size="26" name="yourwebsite"/>
												<br />
												Phone: <input type="text" size="34" name="phone"/>
												<br />
												We reach you:	<input type="radio" name="wereachyou" value="VIAphone" />via phone
																<input type="radio" name="wereachyou" value="VIAemail" />via e-mail
												<br />
												Your experience: <input type="radio" name="seoexperience" value="Nothing" />00% - Nothing
																	 <input type="radio" name="seoexperience" value="ALittleBit" />15% - A little bit
																	 <input type="radio" name="seoexperience" value="Good" />75% - Good
												<br />
												What is your gameplay: <br />
																					<textarea rows="3" cols="150" wrap="physical" name="yourproductsorservices">Write all categories of your products and services</textarea>
											<p></p>
											<p><strong><font color="#b90c31">Section 2</strong> - Informations about your account and expectations</font><br />
											Backend and frontend of the game.</p>
												<code>*  - the job can't be done in just one day - depending by  your preferences<br />
													  **  - 1. Audit to find out problems / 2. A list of things to implement / 3. Implementation of the above list<br />
												      ***  - &lt; 1 month means 3 weeks. For more then 3 years we will discuss after the first 3 years period expires.<br /></code>
												How many days you can wait to finalise jobs:<font color="#b90c31"> *</font>
													<select name="days"> 
														<option>Choose</option> 
														<option>not even one - we working only night</option> 
														<option>2 days</option>
														<option>3 days</option>
														<option>4 days</option>
														<option>5 days</option>
														<option>6 days</option>
													</select>
												<br />
												You will be able to do step 3<font color="#b90c31"> **</font> without our help:
													<select name="step3"> 
														<option>Choose</option>
														<option>yes</option> 
														<option>no (with this option the price will go up)</option>
													</select>
												<br />
												You will sending external signals to raise account alone:
													<select name="raisebusiness"> 
														<option>Choose</option>
														<option>yes</option>
														<option>no</option> 
														<option>I will let you do (with this option the price will go up)</option>
													</select>
												<br />
												The evolution of the account will be further monitored by:
													<select name="evolution">
														<option>Choose</option>
														<option>me</option> 
														<option>you (with this option the price will go up)</option>
													</select>
												<br />	
												How long do you intend to keep your account monitored:<font color="#b90c31"> ***</font>
													<select name="keepaneye">
														<option>Choose</option>
														<option>&lt; 1 month</option> 
														<option>3 months</option>
														<option>6 months</option>
														<option>12 months</option>
														<option>2 years</option>
														<option>3 years</option>
													</select>
												<br />
												How many log in do you have per day:
													<select name="visits">
														<option>Choose</option>
														<option>0-50</option> 
														<option>50-100</option>
														<option>100-300</option>
														<option>500+</option>
														<option>1000+</option>
														<option>3000+</option>
													</select>
											<p></p>
											<p><strong><font color="#b90c31">Section 3</strong> - Validate your informations</font><br />
											Please reconfirm the next informations.</p>
												E-mail confirmation: <input type="email" size="30" name="reconfirmemail">
												<br />
												Your website confirmation: <input type="text" size="23" name="reconfirmyourwebsite" />
												<br />
												Phone confirmation: <input type="text" size="31" name="reconfirmphone" />
												<p></p>
											<input type="submit" name="submit" value="   Request a personal offer   " />
										</form>

MarPlo Mesaje: 4343
Daca apare acel mesaj de la php, inseamna ca e vreo problema la functia mail() de la if() si astfel se executa instructiunea 'else' care genereaza acel mesaj.
Verifica daca email-ul a fost trimis. Daca nu, probabil acel server nu are modulul mail() activat, sau e ceva la variabilele care formeaza parametri.
Pentru verificare trebuie facut un test cu un mesaj simplu, doar cu php, sa vezi daca se trimite email-ul.

Cod: Selectaţi tot

<?php
$to = 'contact@hefferec.ro';
$subject = 'the subject';
$message = 'hello';
$headers = array(
  'From' => 'webmaster@example.com',
  'Reply-To' => 'webmaster@example.com',
  'X-Mailer' => 'PHP/'. phpversion()
);

mail($to, $subject, $message, $headers);
?>

marius91stefan Mesaje: 5
Am incercat sa trimit un mail de pe gmail si acela se vede in cpanel in mail.
Daca schimb sursa din php cu asta ultima tot nu primeste mail si pagina de web dupa ce ii dau send apare goala.

MarPlo Mesaje: 4343
Pagina e goala fiindca acel cod php doar executa instructiunile de trimitere mail; nu are instructiuni de a afisa ceva.
Daca email-ul nu e primit, inseamna ca serverul php nu are modulul mail activat. Adica, php nu trimite mesajul la rularea functiei mail().
In acest caz trebuie vorbit cu administratorul serverului; sa-i arati ultimul cod php si sa-i spui ca email-ul nu se trimite.

marius91stefan Mesaje: 5
Am rezolvat. Multumesc oricum pentru timpul acordat. Am folosit phpmailer pt ca cei de unde am webhostul asa lucreaza. Multumesc inca o data !

Subiecte similare