Good morning,
I state that I am a beginner, I kindly need help from you. I made a page containing a form that submits data to a database. Everything works perfectly. I would now need to send the data to my email address at the same time.
The form contains name, email, text1 text2 and text3. I have tried in every way but without getting any results.
Thanks everyone for the help. A favor to be very simple in the explanation, just because they are at the first steps.

Recommended Answers

This area is well done. But there is no fitting answer because we don't know what email services your web host provides. Reveal a bit more about the web site hosting so I can check them out.

Jump to Post

Since you know each php set of code works why didn't you merge the two? Remember I take it you are a programmer since you didn't put this out as a for hire piece of work.

For example, in your database.php code, at line 27 you have your database updated …

Jump to Post

All 7 Replies

This area is well done. But there is no fitting answer because we don't know what email services your web host provides. Reveal a bit more about the web site hosting so I can check them out.

These are the codes. the first sends the form to email.

email.php

<?php<?php
// Recupero i valori inseriti nel form
$nome = $_POST['nome'];
$email = $_POST['email'];
$titolo = $_POST['titolo'];
$dataeora = $_POST['dataeora'];
$msg = $_POST['msg'];
$url = $_POST['url'];

$delay = "5";
$url = "http://www.myweb.it";

// verifico che tutti i campi siano stati compilati
if (!$nome || !$email || !$titolo || !$dataeora  || !$msg) {
  echo 'Tutti i campi del modulo sono obbligatori!';    
}
// verifico che il nome non contenga caratteri nocivi
elseif (!preg_match('/^[A-Za-z \'-]+$/i',$nome)) {
  echo 'Il nome contiene caratteri non ammessi';    
}
// verifico se un indirizzo email è valido
elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  echo 'Indirizzo email non corretto';
}else{

// compilo un messaggio combinando i dati recuperati dal form
$testo = "Nome: " . $nome . "\n"
       . "Email: " . $email . "\n"
       . "Titolo film: " . $titolo . "\n"
       . "Data e ora spettacolo: " . $dataeora . "\n"       
       . "Messaggio: " . $msg;

// uso la funzione mail di PHP per inviare questi dati al mio indirizzo di posta
mail('mail@altervista.it', 'Reservation', $testo);

// Mostro un messaggio di conferma all'utente
print "<body>
<table align='center' bordercolor='#CCCCCC'>
  <tr>
    <td>
<div align='center'><font face='Verdana, Arial, Helvetica, sans-serif'>
Grazie per aver prenotato</font><br><br>
testo vario <a href='http://www.myweb.it'>Clicca qui</a></font></div></td>
<meta http-equiv='refresh' content='$delay;  url=$url'>
</tr>
</table>
</body>";
}
?>

This submits the form to the database

database.php

<?
//la stringa mysql_connect deve essere compilata con i dati relativi al proprio database
// HOST = IP server Mysql
// USER = Nome utente databse
// PASSWORD = Password utente databse
mysql_connect("localhost","user","password");//database connection
// Qui sotto al posto di NOME_DATABASE, inserite il nome del vostro DB
mysql_select_db("my_user");

// recupero i valori si NOME e INDIRIZZO e li assegno alle variabili $name e $address
$nome = $_POST['nome'];
$email = $_POST['email'];
$titolo = $_POST['titolo'];
$dataeora = $_POST['dataeora'];
$msg = $_POST['msg'];

//inserting data order
$toinsert = "INSERT INTO nome del database
            (nome, email, titolo, dataeora, msg)
            VALUES
            ('$nome',
                         '$email',
                         '$titolo',
                         '$dataeora',
            '$msg')";

//declare in the order variable
$result = mysql_query($toinsert);   //order executes
if($result){
    echo("<br>Inserimento avvenuto correttamente");
} else{
    echo("<br>Inserimento non eseguito");
}
?>



Both work great separately. To do these tests I'm using "altervista.org"
commented: Since you have working code. Is this solved? +15

I wonder if you are stuck on the idea of simultaneously. For most of us, doing one thing then doing the next thing will do nicely.

No, I'm not stuck on simultaneously, but I can't find a workaround. The user who writes on the form, otherwise he would have to do it twice, once to send me an email and once to enter the data in the database. All solutions are well accepted.

Since you know each php set of code works why didn't you merge the two? Remember I take it you are a programmer since you didn't put this out as a for hire piece of work.

For example, in your database.php code, at line 27 you have your database updated so at that point you insert the relevant code (with changes to variable names if need be) from your email.php.

Remember I don't know folk's skill levels or expectations unless they call it out. But it appears you have all the code you need right now. You only need to create a new do-it-all both log to the database (you got that) then after line 27 in database.php perform the email steps from email.php.

No, I'm not a programmer, I'm slowly trying to learn, I'm self-taught, I've created a site just to put into practice I'm learning. But now I just can't go on. If you tell me exactly what the code I need to insert as you suggested after line 27 (database.php) I would be very grateful.

Thanks I solved on the advice of "RPROFFITT" after line 27 or copied the code (email.php). It works perfectly.
I am happy thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.