We help IT Professionals succeed at work.

sending email with PHP for database

arthurbrasileiro
on
29 Views
Last Modified: 2016-05-08
I have this code that sends mail, it must also send a copy to email xxx@email.com. After giving the name and email in a mysql database automatically ...
is it possible?


<?php  // emailform.php enviador por www.experts-exchange.com autor elvin66
// criar sessão para capturar todas as variáveis /////////////////////////////////
session_start();
if(is_array($_REQUEST)) {
              foreach($_REQUEST as $key => $value) {
                        $_SESSION[$key]      = $value;
              }
      }
//*******************// Fim da Sessão //****************************************//
// See if the form has been submitted ////////////////////////////////////////////////////////
if(isset($_POST['submit'])){ //now create the mail form //////////////////////////////////////

$subject = "[OSucessoTeEspera.com] Conferência Online: ".$name.", estou esperando por você!"; // change it to suit

$headers = "MIME-Version: 1.0" . "\r\n"; // don't modify this line
$headers .= "From: " .$email. "\r\n"; // put your from address in here
$headers .= "Reply-To: " .$email. "\r\n"; // put your reply address here
$headers .= "X-Mailer: PHP/" . phpversion();  // don't modify this line
$dia = $_POST['dia'];
$dia_semana = $_POST['dia_semana'];

$entry = 1;
while($entry<6){
$name = $_POST['name'.$entry];
$email1 = $_POST['email'.$entry];
$subject = "[OSucessoTeEspera.com] Conferência Online: ".$name.", estou esperando por você!"; // change it to suit

$message= "Olá ".$name.",\n\n"
."Conforme nossa conversa, agendei a sua participação na próxima conferência online.\n"
."A diferença do nosso trabalho com a Herbalife está nas formas que desenvolvemos essa atividade. É lógico que você precisa de mais informação para saber se realmente é isso que vai permitir você conquistar resultados significativos nessa indústria, por isso, após a conferência vamos conversar mais um pouco.\n\n"
."Acredito que você vai adorar trabalhar conosco!\n"
."Segue o endereço da conferência:\n\n"
."http://conferencia.geracaoh.com/\n"
."LOGIN: geracaoh-".$name."\n"
."SENHA: ".$name."\n\n"
."A Conferência será no dia ".$dia." às 21:00hs (".$dia_semana.")\n"
."Por favor, entre sala com pelo menos 15 minutos de antecedência.\n"
."IMPORTANTE: Será necessário a utilização de áudio (caixa de som ou fones de ouvido)\n\n"
."Sucesso! \n"
.$nome1."\n"
.$email."\n"
.$tels."\n\n";
//$email = $_POST['email'.$entry];

$email_entry = $_POST['name'.$entry]." : ".$_POST['email'.$entry];
if(strlen($email_entry) >3){
if($send_contact = mail($email1,$subject,$message,$headers)) echo "Bom trabalho " .$nome1.", seus emails foram enviados com sucesso!<br>";
}
$entry++;
 }
  }else
  {
//////////////////////////// CREATE THE FORM /////////////////////////////////////////////////


$myform  = "<div align='center'><form action = '' method='POST'>";
$myform .= "<table border=0 cellpadding=3 cellspacing=3 style='font:12pt arial'>";
$myform .= "<tr><td colspan=4><strong>CONVITE CONFERÊNCIA [O Sucesso Te Espera]: Dia: <input type=text name='dia' value=''> :: Semana: <input type=text name='dia_semana' value=''></strong></td></tr>";

// Automate creating the input fields ////////////////////////////////////////////////////////
$i = 1;
while($i<6){
$myform .= "<tr><td></td><td></td>";
$myform .= "<tr><td>Nome</td><td><input type=text name='name".$i."' value=''></td>";
$myform .= "<td>Email</td><td><input type=text name='email".$i."' value=''></td></tr>";
$i++;
}
$myform .= "</tr><td colspan=4 align=center><input type='submit' name='submit' value='ENVIAR'></td></tr>";
$myform .= "</table></form></div>";
echo $myform;
}
?>

Open in new window


Comment
Watch Question

Author

Commented:
I use  the code to include the data in mysql. Want to  join the two codes in a single operation

<link href="http://www.arthurbrasileiro.com.br/recrutamento/themes/Sugar/calendar-win2k-cold-1.css?s=f8fe0e22bdd4756b6af864650c0e07ef&amp;c=1" rel="stylesheet" type="text/css" media="all" mce_href="themes/Sugar/calendar-win2k-cold-1.css?s=f8fe0e22bdd4756b6af864650c0e07ef&amp;c=1"><script src="http://www.arthurbrasileiro.com.br/recrutamento/include/javascript/sugar_grp1.js?s=f8fe0e22bdd4756b6af864650c0e07ef&amp;c=1" type="text/javascript" language="Javascript"></script><script src="http://www.arthurbrasileiro.com.br/recrutamento/jscalendar/lang/calendar-pt.js?s=f8fe0e22bdd4756b6af864650c0e07ef&amp;c=1" type="text/javascript" mce_src="jscalendar/lang/calendar-pt.js?s=f8fe0e22bdd4756b6af864650c0e07ef&amp;c=1"></script><form action="http://arthurbrasileiro.com.br/recrutamento/index.php?entryPoint=WebToLeadCapture" name="WebToLeadForm" method="POST" id="WebToLeadForm"><table class="mceVisualAid" style="border-top: 1px solid; border-bottom: 1px solid; padding: 10px 6px 12px 10px; background-color: rgb(233, 243, 255); font-size: 12px; background-repeat: repeat-x; background-position: center top;" width="100%"><tbody><tr style="color: rgb(0, 105, 225); font-family: Arial,Verdana,Helvetica,sans-serif; font-size: 18px; font-weight: bold; margin-bottom: 0px; margin-top: 0px;" align="center"><td class="mceVisualAid" colspan="4"><b><h2>Web para formulário de potencial cliente para Campanha</h2></b></td></tr><tr style="color: rgb(0, 105, 225); font-family: Arial,Verdana,Helvetica,sans-serif; font-size: 2px; font-weight: normal; margin-bottom: 0px; margin-top: 0px;" align="center"><td class="mceVisualAid" colspan="4">&nbsp;</td></tr><tr style="color: rgb(0, 105, 225); font-family: Arial,Verdana,Helvetica,sans-serif; font-size: 12px; font-weight: normal; margin-bottom: 0px; margin-top: 0px;" align="left"><td class="mceVisualAid" colspan="4">Submeter este formulário irá criar um potencial cliente e uma ligação com a campanha </td></tr><tr style="color: rgb(0, 105, 225); font-family: Arial,Verdana,Helvetica,sans-serif; font-size: 8px; font-weight: normal; margin-bottom: 0px; margin-top: 0px;" align="center"><td class="mceVisualAid" colspan="4">&nbsp;</td></tr><tr><td class="mceVisualAid" style="text-align: left; font-size: 12px; font-weight: normal;" width="15%"><span sugar="slot">Sobrenome: </span><span class="required" style="color: rgb(255, 0, 0);">*</span></td><td class="mceVisualAid" style="font-size: 12px; font-weight: normal;" width="35%"><span sugar="slot"><input gtbfieldid="51" id="last_name" name="last_name" type="text"></span></td><td class="mceVisualAid" style="text-align: left; font-size: 12px; font-weight: normal;" width="15%"><span sugar="slot">&nbsp;</span></td><td class="mceVisualAid" style="font-size: 12px; font-weight: normal;" width="35%"><span sugar="slot">&nbsp;</span></td></tr><tr><td class="mceVisualAid" style="text-align: left; font-size: 12px; font-weight: normal;" width="15%"><span sugar="slot">Endereço Principal Estado: </span></td><td class="mceVisualAid" style="font-size: 12px; font-weight: normal;" width="35%"><span sugar="slot"><input gtbfieldid="52" id="primary_address_state" name="primary_address_state" type="text"></span></td><td class="mceVisualAid" style="text-align: left; font-size: 12px; font-weight: normal;" width="15%"><span sugar="slot">&nbsp;</span></td><td class="mceVisualAid" style="font-size: 12px; font-weight: normal;" width="35%"><span sugar="slot">&nbsp;</span></td></tr><tr><td class="mceVisualAid" style="text-align: left; font-size: 12px; font-weight: normal;" width="15%"><span sugar="slot">Endereço Principal Cidade: </span></td><td class="mceVisualAid" style="font-size: 12px; font-weight: normal;" width="35%"><span sugar="slot"><input gtbfieldid="53" id="primary_address_city" name="primary_address_city" type="text"></span></td><td class="mceVisualAid" style="text-align: left; font-size: 12px; font-weight: normal;" width="15%"><span sugar="slot">&nbsp;</span></td><td class="mceVisualAid" style="font-size: 12px; font-weight: normal;" width="35%"><span sugar="slot">&nbsp;</span></td></tr><tr><td class="mceVisualAid" style="text-align: left; font-size: 12px; font-weight: normal;" width="15%"><span sugar="slot">Telemóvel: </span></td><td class="mceVisualAid" style="font-size: 12px; font-weight: normal;" width="35%"><span sugar="slot"><input gtbfieldid="54" id="phone_mobile" name="phone_mobile" type="text"></span></td><td class="mceVisualAid" style="text-align: left; font-size: 12px; font-weight: normal;" width="15%"><span sugar="slot">&nbsp;</span></td><td class="mceVisualAid" style="font-size: 12px; font-weight: normal;" width="35%"><span sugar="slot">&nbsp;</span></td></tr><tr><td class="mceVisualAid" style="text-align: left; font-size: 12px; font-weight: normal;" width="15%"><span sugar="slot">E-mail: </span></td><td class="mceVisualAid" style="font-size: 12px; font-weight: normal;" width="35%"><span sugar="slot"><input gtbfieldid="55" id="webtolead_email1" name="webtolead_email1" onchange="validateEmailAdd();" type="text"></span></td><td class="mceVisualAid" style="text-align: left; font-size: 12px; font-weight: normal;" width="15%"><span sugar="slot">&nbsp;</span></td><td class="mceVisualAid" style="font-size: 12px; font-weight: normal;" width="35%"><span sugar="slot">&nbsp;</span></td></tr><tr style="color: rgb(0, 105, 225); font-family: Arial,Verdana,Helvetica,sans-serif; font-size: 18px; font-weight: bold; margin-bottom: 0px; margin-top: 0px;" align="center"><td class="mceVisualAid" colspan="4">&nbsp;</td></tr><tr align="center"><td class="mceVisualAid" colspan="10"><input onclick="submit_form();" class="button" name="Submit" value="Submeter" type="button"></td></tr><tr><td class="mceVisualAid" style="display: none;"><input id="campaign_id" name="campaign_id" value="db92fb22-f802-7d7a-7b6a-4c1c19cd01a5" type="hidden"></td></tr><tr><td class="mceVisualAid" style="display: none;"><input id="assigned_user_id" name="assigned_user_id" value="2a18c6b5-a770-f148-89a9-4bd8530ca919" type="hidden"></td></tr><tr><td class="mceVisualAid" style="display: none;"><input id="req_id" name="req_id" value="last_name;" type="hidden"></td></tr></tbody></table></form><script type="text/javascript">
 function submit_form(){
 	if(typeof(validateCaptchaAndSubmit)!='undefined'){
 		validateCaptchaAndSubmit();
 	}else{
 		check_webtolead_fields();
 	}
 }
 function check_webtolead_fields(){
     if(document.getElementById('bool_id') != null){
        var reqs=document.getElementById('bool_id').value;
        bools = reqs.substring(0,reqs.lastIndexOf(';'));
        var bool_fields = new Array();
        var bool_fields = bools.split(';');
        nbr_fields = bool_fields.length;
        for(var i=0;i<nbr_fields;i++){
          if(document.getElementById(bool_fields[i]).value == 'on'){
             document.getElementById(bool_fields[i]).value = 1;
          }
          else{
             document.getElementById(bool_fields[i]).value = 0;
          }
        }
      }
    if(document.getElementById('req_id') != null){
        var reqs=document.getElementById('req_id').value;
        reqs = reqs.substring(0,reqs.lastIndexOf(';'));
        var req_fields = new Array();
        var req_fields = reqs.split(';');
        nbr_fields = req_fields.length;
        var req = true;
        for(var i=0;i<nbr_fields;i++){
          if(document.getElementById(req_fields[i]).value.length <=0 || document.getElementById(req_fields[i]).value==0){
           req = false;
           break;
          }
        }
        if(req){
            document.WebToLeadForm.submit();
            return true;
        }
        else{
          alert('Por favor forneça todos os campos requeridos');
          return false;
         }
        return false
   }
   else{
    document.WebToLeadForm.submit();
   }
}
function validateEmailAdd(){
	if(document.getElementById('webtolead_email1').value.length >0) {
		if(document.getElementById('webtolead_email1').value.match(/^\w+(['\.\-\+]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/) == null){
		  alert('Endereço de e-mail inválido');
		}
	}
	if(document.getElementById('webtolead_email2').value.length >0) {
		if(document.getElementById('webtolead_email2').value.match(/^\w+(['\.\-\+]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/) == null){
		  alert('Endereço de e-mail inválido');
		}
	}
}
</script>

Open in new window

Most Valuable Expert 2011
Author of the Year 2014
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
h4hardySr. Software Enginner

Commented:
Hi,

it's better to add the "cc" in the header section.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.