-1
I have the following code to send email from my form
<?php
// alterar a variavel abaixo colocando o seu email
$destino = "[email protected]";
// emails para quem será enviado o formulário
$assunto = "Contato pelo Site";
// // variaveis
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$subject = $_POST['subject'];
$message = $_POST['message'];
// // monta o e-mail na variavel $body
$body = "===================================" . "\n";
$body .= "Contato - TESTE" . "\n";
$body .= "===================================" . "\n\n";
$body .= "Nome: " . $name . "\n";
$body .= "Email: " . $email . "\n";
$body .= "Telefone: " . $phone . "\n";
$body .= "Assunto: " . $subject . "\n";
$body .= "Mensagem: " . $message . "\n\n";
$body .= "===================================" . "\n";
// // É necessário indicar que o formato do e-mail é html
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'From: $name <$email>';
////envio
mail("$destino, $assunto, $body, $headers");
////confimaçao
echo '<a href="Index.php">Voltar para formulário de cadastro</a>';
?>
and my form code to call this php function is like this
<form action="envio.php" method="post" name="form" class="col-md-9 go-right">
<div class="form-group">
<input id="name" name="name" type="text" class="form-control" required>
<label for="name">Nome</label>
</div>
<div class="form-group">
<input id="email" name="email" type="text" class="form-control" required>
<label for="email">Email</label>
</div>
<div class="form-group">
<input id="phone" name="phone" type="tel" class="form-control" required>
<label for="phone">Celular</label>
</div>
<div class="form-group">
<input id="subject" name="subject" type="text" class="form-control" required>
<label for="subject">Assunto</label>
</div>
<div class="form-group">
<textarea id="message" name="message" class="form-control" required></textarea>
<label for="message">Deixe sua mensagem</label>
</div>
<button type="submit" value="submit">
<input name="submit" value="Enviar"><br>
</button>
</form>
Apparently everything is ok, but when I click 'Send' it loads upload.php as if it were a page, instead of executing the code that is in the file. Of course it gives page not found for sending.php, and the email is not enough, because I believe the code is not running.
Can someone help me? Thank you.
Hello Caroline, a php file should be strictly finished with the extension ". php", make sure that the file extension was not created after that. I suggest looking at the terminal.
– André Lins
Hello André, I took a look here by the terminal and it is right, is sending.php
– Caroline L
You have to see if the mail function is active. Open the
php.ini
, look for the line[mail function]
and adjust the SMTP and smtp_port values.– Augusto Vasques
I believe it is active yes, because I configured through a plugin in WP, and when sending email test by this plugin, it arrives normally. But I’ll take a look at the php.ini file here just to have ctz.
– Caroline L
From what your comment indicates, you are not in trouble, specifically to send email, but rather to interpret a PHP code. When Apache/IIS/Nginx/etc explicitly delivers its source code, it means that PHP is not installed correctly. Obviously this should occur if you access any other page
PHP
in this same environment. Ideal is to first identify what is happening with your environment and then start debugging your email submission script.– LipESprY
Another thing! You are putting the arguments of the call to
mail
in quotes:mail("$destino, $assunto, $body, $headers");
. It’s wrong! You’ve turned what should be multiple arguments into a single argument (string).– LipESprY
Hi, I really don’t. All pages are php and all work normally, php is running ok, but I will make the tips you gave me, if not for sure try this alternative.
– Caroline L
So, another user already informed me, and it’s already changed, and yet, it hasn’t worked.
– Caroline L
So. From now on, your problem is in the interpretation of the file. Make sure that this file is calling the PHP interpreter:
<?php
in the first line. In your question is ok, but it’s worth checking out. - I checked your code by simply fixing the arguments ofmail
and it worked great, although my environment does not actually send the emails. Ahhh! Also try to change the encoding of this file. Usually they are coded in UTF8.– LipESprY
@Augustovasques Vasques checked the php.ini file and is ok
– Caroline L
Fine, I’ll change the encoding. And thanks for the hints. and is in the first line yes the <php?
– Caroline L
Nothing yet, anyone has any other idea ? Thank you
– Caroline L