Good morning! I am having a question, I am sending the data of a form to a Controller that sends an email with such data. However the Controller when mounting the email uses such a function
$body_message = file_get_contents('/email.php');
The email template is very large and so I pull it from another location, however I want to insert variables sent by the form into the template too, how can I do this? I want the form data to be sent to both the controller and the email template.
Contact ArchiveControl.php:
public function enviarEmail(){
$dados = array();
$emailClasse = new Email();
if(isset($_POST['modulo']) && $_POST['modulo'] == "contato"){
$nomeCompleto = $_POST['nome'];
$telefone = $_POST['telefone'];
$empresa = !empty($_POST['empresa']) ? $_POST['empresa'] : " Não informado.";
$cargo = !empty($_POST['cargo']) ? $_POST['cargo'] : " Não informado.";
$email = $_POST['email_corporativo'];
$mensagem = $_POST['mensagem'];
$arr = array(
'properties' => array(
array(
'property' => 'firstname',
'value' => $nomeCompleto
),
array(
'property' => 'email',
'value' => $email
),
array(
'property' => 'phone',
'value' => $telefone
),
array(
'property' => 'company',
'value' => $empresa
)
)
);
$post_json = json_encode($arr);
$hapikey = ("XXXXXXXXXXXXXXXXXXX-XXXXXXXXXXXXX-XXXXXXXXXXXX");
$endpoint = 'https://api.hubapi.com/contacts/v1/contact?hapikey=' . $hapikey;
$ch = @curl_init();
@curl_setopt($ch, CURLOPT_POST, true);
@curl_setopt($ch, CURLOPT_POSTFIELDS, $post_json);
@curl_setopt($ch, CURLOPT_URL, $endpoint);
@curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = @curl_exec($ch);
$status_code = @curl_getinfo($ch, CURLINFO_HTTP_CODE);
$curl_errors = curl_error($ch);
@curl_close($ch);
$subject = " xxxx- Contato ";
$body_message = file_get_contents('/email.html');
$headers = 'De: '.$email."\r\n";
$headers .= 'Reply-To: '.$email."\r\n";
$mail_status = mail('[email protected]',$subject,$body_message,$headers);
if($respostaEnvio){
$dados['mensagem'] = "Contato enviado com sucesso. Aguarde que logo te enviaremos uma resposta.";
}else{
$dados['mensagem'] = "Não foi possível enviar a mensagem no momento. Tente mais tarde.";
}
}
The email code is in the link below the pastebin because it did not fit the question: link