Jump to content


New Members
  • Posts

  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

Jen2002's Achievements


Newbie (1/5)




Community Answers

  1. When I set the browser langauge to any other language than "en" (like "it", "da",...) echo always output "en" ? <?php $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2); if ($lang = "en") { echo $lang; } else { echo "Other lang"; } ?>
  2. Yes it works, by default, data passed in to the data option as an object (technically, anything other than a string) will be processed and transformed into a query string, fitting to the default content-type "application/x-www-form-urlencoded". If you want to send a DOMDocument, which is the case here, set this option to false.
  3. Found out what was going wrong thanks to F12...Attachment [object] was always null so I added these two lines in my Ajax code: processData: false, contentType: false,
  4. I think the problem I have with this situation, it's the email that is sent with all the other informations. After submitting the form I receive no error, and the email lands in my inbox, but no attachment ?
  5. Before with the serialize() function it was the case, then I switch to data: new FormData(this), to grab all form contents including the uploaded files... I will read about move_uploaded_file, and try it tomorrow at lunch...will post back result Thanks
  6. I want to send an attachement file by the user from an html form and send it by email with PHPMailer. I can send every input, except the attachement, can you please help... Here's my HTML form code ... <div class="form-group"> <input type="file" id="Attachment" class="form-control-textarea" placeholder=" Upload file:" name="Attachment" style="text-decoration: underline"></input> </div> <div class="form-group"> <button onClick="sendContact();" type="button" class="form-control-submit-button" name="submit">Submit</button> </div> </form> Now the Jquery that send form inputs to PHPMailer: <script src="https://code.jquery.com/jquery-2.1.1.min.js" type="text/javascript"></script> <script type="text/javascript"> function sendContact() { var valid; valid = validateContact(); if(valid) { jQuery.ajax( { url: "mail_handler.php", /*data: $("#ContactFrm").serialize(), */ data: new FormData(this), // grab all form contents including files type: "POST", success:function(data) { $("#feedback").html(data); I use FormData() to grab the file information. Finally the PHP code: $file_to_attach = $_FILES['Attachment']['tmp_name']; $filename = $_FILES['Attachment']['name']; $mail = new PHPMailer(); $mail->IsSMTP(); $mail->addAttachment($file_to_attach, $filename); Like I said email is sent but no attachment... Thanks
  7. Hello, I'm starting with PHP, and I was working on a personnal project using AJAX. Here is my simple HTML form with 3 fields and a button, I was hopping sending email and giving the user the feedback without refreshing the page: ************************************************************************** <!-- Contact Form --> <form action="" method="post" id="ContactFrm"> <div class="form-group"> <input id="name" type="text" class="form-control-input" placeholder="Name" name="Name" required> </div> <div class="form-group"> <input id="email" type="email" class="form-control-input" placeholder="Email" name="Email" required> </div> <div class="form-group"> <textarea id="message" class="form-control-textarea" placeholder="Message" name="Message" required></textarea> </div> <div class="form-group"> <button id="submitBtn" type="button" class="form-control-submit-button" name="submit" value="submit">Submit</button> </div> </form> <center><div id="feedback" class="form-control-input"></div></center> ************************************************************************** Here is the script in the head section: <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function () { $('.submitBtn').click(function (e) { e.preventDefault(); $.ajax ({ type: "POST", url: "mail_handler.php", data: $('ContactFrm').serialize(), success: function (html) { alert('form was submitted'); //$('#ContactFrm')[0].reset(); } }); }); }); </script> *************************************************************** And finally this is my mail_handler.php using PHPMailer wich works fine until I added the Ajax part calling the PHP: <?php error_reporting(E_ALL); ini_set('display_errors', 1); #load phpmailer use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; use PHPMailer\PHPMailer\SMTP; require 'vendor/Exception.php'; require 'vendor/PHPMailer.php'; require 'vendor/SMTP.php'; #Receive user input $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; $mail = new PHPMailer(); $mail->IsSMTP(); $mail->SMTPDebug = 1; $mail->Host = 'mail.jelaweb.com'; $mail->Port = 587; $mail->SMTPSecure = 'tls'; $mail->SMTPAuth = false; $mail->From = $email; $mail->AddAddress('info@jelaweb.com'); $mail->Subject = "Hello"; $mail->Body = $message; $mail->IsHTML(false); if (!$mail->send()) { echo $mail->ErrorInfo; echo"<p>The mail() function failed.</p>"; } else { echo"<p>Email Sent !!!</p>\n"; } ?> ************************************************************* For some unknown reasons the call do not transfer fileds values to php, giving the error : PHP Notice: Undefined index: for name, email and message. I've been working for a while on this bug and tried a lot of things but can't get the message in the feedback section of the form. Thanks in advance for nay help.
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.