John Davidson

codeigniter - $post is not sending an email ASP / PHP

0 comments
Message:


i have call me modal on website. (im havent created it im just fixing some stuff)
so, this modal has to receive user input like name, surname, phone and date when they want to receive call and send it to our email here is the code:


 <div class="recall-button" data-toggle="modal" data-target="#reCallMe"><img src="<?=$url?>assets/images/headset.png" alt="" /></div>
<div class="modal fade" id="reCallMe" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel"><?=lang('reCall')?></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<label><?=lang('reCallNameLastname')?></label>
<input name="name" class="form-control" type="text" placeholder="<?=lang('reCallNameLastname')?>" required >
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<label><?=lang('reCallPhone')?></label>
<input name="url" type="hidden" value="<?=$url.$lang?>" >
<input name="phone" class="form-control" type="number" placeholder="<?=lang('reCallPhone')?>" required >
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<label><?=lang('reCallDate')?></label>
<input name="datetime" id="date" class="form-control" type="text" value="<?=date("d/m/Y H:i")?>" required >
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="input-group google-re">
<?php echo $widget2;?>
<?php echo $script2;?>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary recallme" name="reCallMe" data-close="<?=lang('close')?>" value="1"><?=lang('reCallSend')?></button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="subscribeMeBlock" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
</div>
<div class="modal-body">
<h5 class="modal-title" id="exampleModalLabel"><?=lang('newSubscriber')?></h5>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary closeSubscribeMeBlock" data-dismiss="modal"><?=lang('close')?></button>
</div>
</div>
</div>
</div>



here is what controls sending of this filled form:


public function success_mail() {

$status = lang('error');

$this->load->library('recaptcha');
$recaptcha = $this->input->post('g-recaptcha-response');

if (($this->input->post('name') != "") && ($this->input->post('phone') != "") && ($this->input->post('datetime') != "")) {
if (!empty($recaptcha)) {

$response = $this->recaptcha->verifyResponse($recaptcha);
if (isset($response['success']) and $response['success'] == "1") {

$post = $this->input->post();
$message = "name, surname: ".$post['name']."\n"."phone: ".$post['phone']."\n"."call time: ".$post['datetime']."\n";

$this->load->library('email');
$this->email->from('[email protected]', "");
// $this->email->to($data['contact_mail']);
$this->email->to('[email protected]');
$this->email->subject("callme");
$this->email->message($message);
$this->email->send();

$status = lang('wait_call');
} else {
$status = lang('error');
}
} else {
$status = lang('error');
}
} elseif($this->input->post('subscribeMe') != "") {

$email = $this->input->post('subscribeMe');

if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$email = "0";
}

if ($email != '0') {
$ifIssetMail = $this->Main_Model->IfIssetSubscribeMail($email);
if ($ifIssetMail == '0') $this->Main_Model->AddSubscribeMail($email);
}

$status = lang('newSubscriber');

} else {
$status = lang('error');
}

echo $status;
}

now,my problem is, button does nothing at all, can i know why?



My Answer:
php
if(isset($_POST['submit'])){
$name = $_POST['name'];
$surname = $_POST['surname'];
$phone = $_POST['phone'];
$date = $_POST['date'];

$to = "[email protected]";
$subject = "Call me request";
$message = "Name: $name\nSurname: $surname\nPhone: $phone\nDate: $date";

$headers = "From: $name <$email>";

if(mail($to, $subject, $message, $headers)){
echo "Email sent successfully";
} else {
echo "Email sending failed";
}
}
?>


Make sure to replace `"[email protected]"` with your actual email address. Also, ensure that your server is properly configured to send emails.

Rate this post

4 of 5 based on 2575 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us