0
Thank you for your attention! Well I don’t have much familiarity with programming just with design. I tried to use the Phpmailer class to create a simple contact form on my site, I looked here for some tips but I was not very successful, because everything I saw was a little early and I could not learn the basics...
I even installed the Composer and install the phpmailer for it but I locked there and I could not follow alone, I ask for help here if someone points out to me what I am doing wrong and how to fix would thank a lot.
CONTACT.HTML
<form id="form" action="vendor/sendmail.php" method="post">
<div class="field">
<label class="label">Name</label>
<div class="control">
<input class="input" type="text" name="nome" placeholder="Name">
</div>
</div>
<div class="field">
<label class="label">Email</label>
<div class="control">
<input class="input" type="email" name="email" placeholder="Email">
</div>
</div>
<div class="field">
<label class="label">Message</label>
<div class="control">
<textarea class="textarea" name="mensagem" placeholder="Message"></textarea>
</div>
</div>
<div class="field is-grouped">
<div class="control">
<button class="button is-link">Submit</button>
</div>
</div>
</form>
SENDMAIL.PHP (I took it exactly as it was in the documentation and I just filled in my data) <? php // Import Phpmailer classes into the global namespace
$nome = $_POST["nome"];
$email = $_POST["email"];
$mensagem = $_POST["mensagem"];
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
//Load Composer's autoloader
require 'autoload.php';
$mail = new PHPMailer(true); // Passing `true` enables exceptions
try {
//Server settings
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'mail.eftmkg.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '[email protected]'; // SMTP username
$mail->Password = 'xxxxxxxxxxxx'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('[email protected]', 'Mailer');
$mail->addAddress('[email protected]', 'Kaio Maia'); // Add a recipient
$mail->addAddress('[email protected]'); // Name is optional
$mail->addReplyTo('[email protected]', 'Info');
//$mail->addCC('[email protected]');
//$mail->addBCC('[email protected]');
//Attachments
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
//Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'EFTMKG';
$mail->Body = '$mensagem';
//$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
When I try to send I get the error message:
Could not access file: /var/tmp/file.tar.gz
Message could not be sent. Mailer Error: Could not access file: /var/tmp/file.tar.gz
The attachments are part of the email, if this file does not exist it will not give correct preventing the email.
– I_like_trains
Have you checked the site yourself? It has several similar answers, it may help you: this one: https://answall.com/questions/153820/phpmailer-erro-ao-enviar , and this one for example: https://answall.com/questions/229703/envio-de-anexo-com-phpmailer
– Ricardo Pontual
Ricardo I researched yes, but as I have no notion of programming, any term in the code that is different from my already find some difficulty to understand...
– Kaio Maia