I advise you rather use ready Mailer class for that - http://phpmailer.worxware.com/ is the best choice. I use it for many years and you can configure SMTP connection very easy
How do i configure my contact form to receive messages
-
13-07-2023 - |
题
I am trying to configure my contact from to my remote server. The technical guys from my hosting have issued me this settings for my mail setting:
(POP3/IMAP) & outgoing mail (SMTP) server name is: mail.yourdomain.com ports are: POP3 -> 110, IMAP -> 143 and SMTP -> 25 or 2525
Unfortunately, i do not know where to insert that into my php contact file.
these are the contact files:
contact.html
<form role="form" action="contact.php" method="post">
<div class="text-fields">
<div class="form-group">
<input type="text" class="form-control" name="bbname" id="bbname" placeholder="name:">
</div>
<div class="form-group">
<input type="email" class="form-control" name="bbemail" id="bbemail" placeholder="email:">
</div>
<div class="form-group">
<input type="text" class="form-control" name="bbphone" id="bbphone" placeholder="phone:">
</div>
</div>
<div class="submit-area">
<div class="form-group">
<textarea class="form-control" placeholder="message:" name="bbmessage" id="bbmessage"></textarea>
</div>
<button type="submit" class="btn btn-default" id="bbsubmit">Send it</button>
</div>
</form>
contact.php
<?php
$field_name = $_POST['bbname'];
$field_email = $_POST['bbemail'];
$field_phone = $_POST['bbphone'];
$field_message = $_POST['bbmessage'];
$mail_to = 'me@mydomain.com';
$subject = 'Message from '.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Phone: '.$field_phone."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. I will contact you shortly.');
window.location = 'contact.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to me@mail.com');
window.location = 'contact.html';
</script>
<?php
}
?>
解决方案
不隶属于 StackOverflow