$id = $_POST['id'];
$to="codieboi#mail.com";
$msg1="done";
$email_subject = "View Cateloge Request";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'X-MSMail-Priority: High'. "\r\n";
$headers = 'From: '.$_POST['email']."\r\n".
'X-Mailer: PHP/' . phpversion();
$email_message .= "Name: ".$_POST['fname']."\n";
$email_message .= "Email: ".$_POST['email']."\n";
$email_message .= "Phone: ".$_POST['phone']."\n";
$email_message .= "Phone: ".$_POST['message']."\n";
#mail($to, $email_subject, $email_message, $headers);
$link = the_field('upload_file', $id);
echo '<script type="text/javascript">var url="_________";var win = window.open(url, "_blank");win.focus();</script>';
I store a url dynamically to the variable "link". I want to open up it in a new tab, once the mail is send. This is the code I have written. I need to place url in the _____________.
Please help.
If you store url to variable link, just use it:
echo "<script type='text/javascript'>var url='". $link."';var win = window.open(url, '_blank');win.focus();</script>";
Related
I want to redirect the user to another page only after displaying a success message. The code below redirects to the another page even if the page is refreshed without submitting any data.
Code Snippet
<?php
// We will store our status message later
$message = '';
// Let's check form submitted
if( isset( $_POST['action'] ) && $_POST['action'] == 'submit' ) {
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['number'];
$message_text = $_POST['address'];
if (isset($_POST['action']))
{
// Validate required fields
if( $name == '' || $email == '' || $message_text == '' ){
$message = "<p class=\"error\">Please fill out all required fields.</p>";
}
// send email after validation
else {
// Email will be sent at this email
$mailto = 'nepstarditsolutions#gmail.com';
// Let's create html email format
// (You can use html in this email format)
// Email headers
$headers = "From: " . strip_tags( $email ) . "\r\n";
$headers .= "Reply-To: ". strip_tags( $email ) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
// Email body
$message = "<html><body>";
$message .= "<h3>Contact Info: </h3>";
$message .= "<p><strong>Name: </strong> ". strip_tags( $name ) . "</p>\r\n";
$message .= "<p><strong>Email: </strong> ". strip_tags( $email ) . "</p>\r\n";
$message .= "<p><strong>Contact Number: </strong> ". strip_tags( $phone ) . "</p>\r\n";
$message .= "<p><strong>Alternate Email: </strong> ". strip_tags( $_POST['altemail'] ) . "</p>\r\n";
$message .= "<p><strong>Hosting Package: </strong> ". strip_tags( $_POST['cradio'] ) . "</p>\r\n";
$message .= "<p><strong>Address: </strong>". strip_tags( $message_text ) . "</p>\r\n";
$message .= "</body></html>";
// Email subject
$subject = "Contact Info from ".$name;
// Send email
$mail_status = #mail( $mailto, $subject, $message, $headers );
if( $mail_status ){
$message = '<div class="alert alert-success">Quotation submitted Successfully ! </div>';
}
else {
$message = '<div class="alert alert-danger">Error in sending the Quotation ! </div>';
}
}
}
}
?>
I need help in 2 things
Success message should be displayed for 2 seconds (before the redirect).
How to redirect using JS in php?
Standard "vanilla" JavaScript way to redirect a page
You can use the code below to redirect the user after form submission code.
if( $mail_status ){
echo "
<script>
setTimeout(function() {
window.location = 'http://www.example.com/newlocation';
}, 2000);
</script>
";
}
MDN web docs on how setTimeout works
Hope it helps!
i am having a problem to do a webhook with the facebook api on a lead ads form.
Last day it was working like a charm. On the 'Lead Ads Testing Tool' i received a status = success. Now i received a status = failure, error code = 102, error message = server failure
image of the error 102
Anyone know this issue ?
here my webhook.php :
if (isset($_GET['hub_verify_token'])) {
if ($_GET['hub_verify_token'] === 'your verify token') {
echo $_GET['hub_challenge'];
return;
} else {
echo 'Invalid Verify Token';
return;
}
}
$input = json_decode(file_get_contents('php://input'), true);
$emailfrom = "test#test.com";
$emailto = "my#email.com";
$subject = "You've got a new submission Test";
$headers = "From: " . $emailfrom . "\r";
$headers .= "Reply-To: ". $emailfrom . "\r";
$headers .= "MIME-Version: 1.0\r";
$headers .= "Content-Type: text/html; charset=utf-8\r";
$body = 'hello';
mail($emailto, $subject, $body, $headers);
and the callback_url is good = "success": true image graph api subscription to webhook
Thanks
I have this simple form code here
<?php
$EmailFrom = "form#form.com";
$EmailTo = "s#outlook.com";
$Subject = "Form";
$Name = Trim(stripslashes($_POST['Name']));
$Budget = Trim(stripslashes($_POST['Budget']));
$Email = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Budget: ";
$Body .= $Budget;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
And I was wondering how to make the from address in the top the same as the one submitted.
If I understand correctly, you can do away entirely with this variable:
$EmailFrom = "form#form.com";
And this revised mail() function should do what you're asking:
// send email
$success = mail($EmailTo, $Subject, $Body, "From: " . $Email . "\r\n");
Note I've used the following variable you've already declared:
$Email = Trim(stripslashes($_POST['Email']));
I wrote code to send emails from PHP using HTML and JavaScript (jQuery). In js I defined the following strings:
var firstT = "It is " + $("#time").html() + " right now.";
var secondT = "And now, it is " + $("#othTime").html() + ".";
var sendT = firstT + "\r\n" + secondT;
Then I send this string to the PHP file:
var thTi = "folder/time.php?to=" + $("#perName").val() + "&message=" + sendT;
$.ajax({
url: thTi
});
PHP receives this strings and sends it with this code:
<?php
$to = $_GET['to'];
$subject = "The Subject";
$message = $_GET['message'];
$headers = 'From: Me?' . "\r\n" .
'Reply-To: no-reply#thesite.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
So, the problem is - when a person receives the message, it is all in one line. I've added line breaks \r\n, even tried with <br> and <br />. I found somewhere that inserting a dot . might solve the problem, but I've tried, and it doesn't.
To send an html email with mail(), you have to add the proper headers:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'From: Me?' . "\r\n";
$headers .= 'Reply-To: no-reply#thesite.com' . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
To clean and add line-breaks to your html:
$message = strip_tags($_GET['message'];);
$message_html = preg_replace('/\n/' , '<br />' , $message);
Use the double quotes " instead of ' and then \r\n will work. So your new code must looks like:
$headers = "From: Me?" . "\r\n" .
"Reply-To: no-reply#thesite.com" . "\r\n" .
"X-Mailer: PHP/" . phpversion();
Since you are using an html tages in your mail first thing that you need to do is to set an header type of that mail to html. Append the below lines to the code to the $header variable at the start, before adding the from and other details in this variable.
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: Me?' . "\r\n" .
'Reply-To: no-reply#thesite.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
for more understanding of this you can see this link: http://www.w3schools.com/php/func_mail_mail.asp
I hope this helps you.
I have PHP code that help me to other people can be in touch with me and send their opinion to me .
here's my PHP code :
<?php
$to = 'ticket.ritaweb#gmail.com';
$subject = 'Your decision/Opinion';
$name = htmlspecialchars($_REQUEST['name']);
$email = htmlspecialchars($_REQUEST['email']);
$site = htmlspecialchars($_REQUEST['site']);
$mobile = htmlspecialchars($_REQUEST['mobile']);
$nazar = htmlspecialchars($_REQUEST['nazar']);
$sqt = '2164854';
$sqtin = htmlspecialchars($_REQUEST['sqtin']);
if ($sqt === $sqtin) {
function clean_string($string) {
$bad = array("content-
type", "bcc:", "to:", "cc:", "href");
return str_replace($bad, "", $string);
}
$email_message .= "name : " . clean_string($name) . "\n";
$email_message .= "email : " . clean_string($email) . "\n";
$email_message .= "address : " . clean_string($site) . "\n";
$email_message .= "number : " . clean_string($mobile) . "\n";
$email_message .= "opinion : " . clean_string($nazar) . "\n";
$headers = 'From: ' . $mobile . "\r\n" . 'Reply-To: ' . $email . "\r\n" . 'X-Mailer:
PHP/' . phpversion();
mail($to, $subject, $email_message, $headers);
}
?>
and I called it with javascript ( ajax ) but I want a code in ajax that help me If my condition in PHP file was FALSE or each of the field was empty , show the message : "Your message was not send, be careful".
and here's my AJAX code :
<script type="text/javascript">
$(document).ready(function() {
$('#submit').click(function() {
$('#submit').attr('value', 'sending...');
$.post("themes/RitaWeb-v1/send.php", $(".rita_form").serialize(),
function(response) {
$('#submit').attr('value', 'sent.');
});
return false;
});
});
</script>
Use PHP to print messages on the page, like
{'status' : 'success'}
if the mail was sent and
{'status' : 'error'}
Then do something based on the output with js.
EDIT:
If you use jQuery.ajax instead of jQuery.post,you can also use the settings argument to let something happen if there ared errors during the request.
More information: http://api.jquery.com/jquery.ajax/
In your code, it would look like this.
PHP:
...
mail($to, $subject, $email_message, $headers);
print('{"status":"success"}');
}
else{
print('{"status":"error"}');
}
And your js:
$.ajax('themes/RitaWeb-v1/send.php').done(function(data){
status = $.parseJSON(data).status;
if(status == 'success'){
// do something
}
else if(ststus == 'error'){
// do something
}
else{
alert('unknown response');
}
});