ianhaney10 Posted 15 hours ago Share Posted 15 hours ago Hi I am trying to use phpmailer without the smtp credentials as the client does not know the email password or they don't have it to hand so trying to use phpmailer without the smtp info, I am trying the following code and not getting any errors and it's going to the enquiry confirmation page but the email is not coming through <?php session_start(); use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; // Include PHPMailer 6.x autoloader require 'PHPMailer/src/Exception.php'; require 'PHPMailer/src/PHPMailer.php'; require 'PHPMailer/src/SMTP.php'; $name = ''; $phone = ''; $email = ''; $message = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $name = $_POST['name']; $phone = $_POST['phone']; $email = $_POST['email']; $message = $_POST['message']; $error=''; if(!$name || !$phone || !$email || !$message){ $error.="**Please fill the fields.!".'<br>'; } if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $error.="**Please enter valid email address.".'<br>'; } if(!$error){ // Initialize PHPMailer $mail = new PHPMailer(true); try { $mail->SMTPDebug = 0; // Enable verbose debug output / Enable SMTP debug information (for testing) //$mail->isSMTP(); // Set mailer to use SMTP //$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers //$mail->SMTPAuth = true; // Enable SMTP authentication //$mail->Username = ''; // SMTP username //$mail->Password = ''; // SMTP password //$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted //$mail->Port = 587; // TCP port to connect to $mail->setFrom('[email protected]', "Company Name"); $mail->addAddress('[email protected]', "Company Name"); // Add a recipient $mail->addReplyTo($_POST['email'], $_POST['name']); $mail->isHTML(false); // Set email format to HTML $mail->Subject = 'New Website Enquiry'; $mail->Body = "A new website enquiry has been made. The enquiry information is below\r\n\r\n" . "Name: " . $_POST["name"] . "\r\n" . "Phone: " . $_POST["phone"] . "\r\n" . "Email: " . $_POST["email"] . "\r\n" . "Message: " . $_POST["message"]; $mail->send(); // Redirect upon successful sending header("Location: http://domainname.co.uk/enquiry-confirmation.php"); exit(); } catch (Exception $e) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; } } } ?> <form action="#form-section" method="post"> <div class="row"> <div class="col-sm-6 col-lg-6"> <div class="form-group"> <input type="text" value="<?php echo $name; ?>" name="name" id="name" class="form-control" required placeholder="Name"> </div> </div> <div class="col-sm-6 col-lg-6"> <div class="form-group"> <input type="text" value="<?php echo $phone; ?>" name="phone" id="phone" class="form-control" placeholder="Phone"> </div> </div> <div class="col-sm-12 col-lg-12"> <div class="form-group"> <input type="email" value="<?php echo $email; ?>" name="email" id="email" class="form-control" required placeholder="Email"> </div> </div> <div class="col-md-12 col-lg-12"> <div class="form-group"> <textarea name="message" class="form-control" cols="30" rows="8" required placeholder="Message" value="<?php echo $message; ?>"></textarea> </div> </div> <div class="col-md-12 col-lg-12"> <button type="submit" id="submit" name="submit" class="contact-btn btn">Send Message</button> <div class="clearfix"></div> </div> </div> </form> Can anyone see where I have gone wrong please as been trying for hours and can't see what the issue is Quote Link to comment https://forums.phpfreaks.com/topic/327519-send-email-with-phpmailer-not-using-smtp-issue/ Share on other sites More sharing options...
mac_gyver Posted 14 hours ago Share Posted 14 hours ago the php mail() function and the phpmailer/swiftmailer classes allow php to act like an email client, to send an email to a mail server. when you don't use smtp authentication against a mail box on that mail server, that mail server must be configured to "trust" the (ip address of the) web server where the php code is running. typically, a local mail server at web hosting is configured this way. if you are not getting any errors back, it is likely that the locally configured mail server is setup to silently accept emails, regardless of it it intends to send them, without returning an error. where are you running this php code at? a localhost development system or web hosting, and if on web hosting is the domain name in the From: address hosted at the sending web server or is it hosted at some other location? Quote Link to comment https://forums.phpfreaks.com/topic/327519-send-email-with-phpmailer-not-using-smtp-issue/#findComment-1653402 Share on other sites More sharing options...
ianhaney10 Posted 14 hours ago Author Share Posted 14 hours ago 5 minutes ago, mac_gyver said: the php mail() function and the phpmailer/swiftmailer classes allow php to act like an email client, to send an email to a mail server. when you don't use smtp authentication against a mail box on that mail server, that mail server must be configured to "trust" the (ip address of the) web server where the php code is running. typically, a local mail server at web hosting is configured this way. if you are not getting any errors back, it is likely that the locally configured mail server is setup to silently accept emails, regardless of it it intends to send them, without returning an error. where are you running this php code at? a localhost development system or web hosting, and if on web hosting is the domain name in the From: address hosted at the sending web server or is it hosted at some other location? Ahh ok sounds like it could be that and silently accepting emails. It's on the web hosting with hostgator. It's in the web hosting cPanel but it still don't seem to be sending, I'm using my email address at the moment as a test and it's not coming through so for some reason it don't seem to be sending the email Quote Link to comment https://forums.phpfreaks.com/topic/327519-send-email-with-phpmailer-not-using-smtp-issue/#findComment-1653403 Share on other sites More sharing options...
mac_gyver Posted 12 hours ago Share Posted 12 hours ago this is a 'contact us' form. for the client to be able to receive and read the emails, they must be sent to an email address that the client has access to. is this To: address at their web hosting (mail_box_name@their_doman_name) or somewhere else, such as a gmail address ([email protected])? i didn't find any information about using unauthenticated smtp at hostgator, but if this is possible, it would require an email account to be created within cpanel for the domain name that's hosted at hostgator, then this email address would be used as the From: address. the To: address can then be anywhere, even the same as the From: address. everything I saw about hostgator email used smtp authentication, which needs an email account to be created within cpanel for the domain name hosted at hostgator, with the password known. if they have an email address at their domain name, but the password is not known, it needs to be reset to a known value within cpanel. for php to be able to send to (the From: and To: addresses would be the same and be the email account at hostgator) or through (the From: address would be the email account at hostgator and the To: can be anywhere) the mail server at hostgator, you would use the hostgator server settings. see the cPanel Emails, Outgoing Email Settings at this link - https://www.hostgator.com/help/article/email-connection-settings#cpanelemails you can, using the phpmailer/swiftmailer class, send an email to or through an external mail server, such as gmail, but this requires the username/password of the account on that external mail server. Quote Link to comment https://forums.phpfreaks.com/topic/327519-send-email-with-phpmailer-not-using-smtp-issue/#findComment-1653406 Share on other sites More sharing options...
ianhaney10 Posted 12 hours ago Author Share Posted 12 hours ago 9 minutes ago, mac_gyver said: this is a 'contact us' form. for the client to be able to receive and read the emails, they must be sent to an email address that the client has access to. is this To: address at their web hosting (mail_box_name@their_doman_name) or somewhere else, such as a gmail address ([email protected])? i didn't find any information about using unauthenticated smtp at hostgator, but if this is possible, it would require an email account to be created within cpanel for the domain name that's hosted at hostgator, then this email address would be used as the From: address. the To: address can then be anywhere, even the same as the From: address. everything I saw about hostgator email used smtp authentication, which needs an email account to be created within cpanel for the domain name hosted at hostgator, with the password known. if they have an email address at their domain name, but the password is not known, it needs to be reset to a known value within cpanel. for php to be able to send to (the From: and To: addresses would be the same and be the email account at hostgator) or through (the From: address would be the email account at hostgator and the To: can be anywhere) the mail server at hostgator, you would use the hostgator server settings. see the cPanel Emails, Outgoing Email Settings at this link - https://www.hostgator.com/help/article/email-connection-settings#cpanelemails you can, using the phpmailer/swiftmailer class, send an email to or through an external mail server, such as gmail, but this requires the username/password of the account on that external mail server. Thank you, I'm trying a different way until can sort the other email address out. a gmail email address has been set up and trying that and from what I read online, a app password needs to be created and use that within phpmailer settings instead of the password used to create the email address Quote Link to comment https://forums.phpfreaks.com/topic/327519-send-email-with-phpmailer-not-using-smtp-issue/#findComment-1653407 Share on other sites More sharing options...
maxxd Posted 9 hours ago Share Posted 9 hours ago I hosted on HostGator for a while quite a few years ago and if I'm not mistaken, you needed to authenticate the SMTP requests or emails would just fly out into the ether. Quote Link to comment https://forums.phpfreaks.com/topic/327519-send-email-with-phpmailer-not-using-smtp-issue/#findComment-1653415 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.