Hello,
I've tried making my contact form work with PHP and SMTP, but none have worked.
With PHP, I get the:
Email could not be sent due to some Unexpected Error. Please Try Again later.
Reason:
Could not instantiate mail function.
I read in previous tickets that this could be a server issue, so to then try with SMTP settings, but when I entered the settings in my form.php file, the form just greys out and seems to be loading, but times out after a while and nothing happens.
I've attached screenshots for both instances.
Here is my form code:
<div class="form-widget mt-5 mx-auto" style="max-width: 750px">
<div class="form-result"></div>
<form class="row mb-0" id="template-contactform" name="template-contactform" action="include/form.php" method="post">
<div class="form-process">
<div class="css3-spinner">
<div class="css3-spinner-scaler"></div>
</div>
</div>
<div class="col-md-6 form-group">
<label class="text-transform-none" for="template-contactform-name">Name <small>*</small></label>
<input type="text" id="template-contactform-name" name="template-contactform-name" value="" class="form-control required">
</div>
<div class="col-md-6 form-group">
<label class="text-transform-none" for="template-contactform-email">Email <small>*</small></label>
<input type="email" id="template-contactform-email" name="template-contactform-email" value="" class="required email form-control">
</div>
<div class="clear"></div>
<div class="col-12 form-group">
<label class="text-transform-none" for="template-contactform-phone">Phone</label>
<input type="text" id="template-contactform-phone" name="template-contactform-phone" value="" class="form-control">
</div>
<div class="col-12 form-group">
<label class="text-transform-none" for="template-contactform-message">Message <small>*</small></label>
<textarea class="required form-control" id="template-contactform-message" name="template-contactform-message" rows="6" cols="30"></textarea>
</div>
<div class="col-12 form-group d-none">
<input type="text" id="template-contactform-botcheck" name="template-contactform-botcheck" value="" class="form-control">
</div>
<div class="col-12 form-group">
<button class="button button-rounded button-large m-0" type="submit" id="template-contactform-submit" name="template-contactform-submit" value="submit">Send Message</button>
</div>
<input type="hidden" name="prefix" value="template-contactform-">
</form>
</div>And here is the form.php code:
/*-------------------------------------------------
PHPMailer Initialization
---------------------------------------------------*/
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'phpmailer/src/Exception.php';
require 'phpmailer/src/PHPMailer.php';
require 'phpmailer/src/SMTP.php';
/*-------------------------------------------------
Receiver's Email
---------------------------------------------------*/
$toemails = array();
$toemails[] = array(
'email' => 'hello@yycbestrenos.ca', // Your Email Address
'name' => 'YYC Best Renos' // Your Name
);
/*-------------------------------------------------
Sender's Email
---------------------------------------------------*/
$fromemail = array(
'email' => 'hello@yycbestrenos.ca', // Company's Email Address (preferably currently used Domain Name)
'name' => 'YYC Best Renos' // Company Name
);
/*-------------------------------------------------
reCaptcha
---------------------------------------------------*/
// Add this only if you use reCaptcha with your Contact Forms
$recaptcha_secret = ''; // Your reCaptcha Secret
/*-------------------------------------------------
hCaptcha
---------------------------------------------------*/
// Add this only if you use hCaptcha with your Contact Forms
$hcaptcha_secret = ''; // Your hCaptcha Secret
/*-------------------------------------------------
PHPMailer Initialization
---------------------------------------------------*/
$mail = new PHPMailer();
/* Add your SMTP Codes after this Line */
$mail->IsSMTP();
$mail->Host = "email.yycbestrenos.ca";
$mail->SMTPDebug = 0;
$mail->SMTPAuth = true;
$mail->SMTPSecure = "ssl";
$mail->Port = 26;
$mail->Username = "hello@yycbestrenos.ca";
$mail->Password = "*MyPassword*";
// End of SMTP