Currently, I have a directory website that expiry notices to users. I would like to be able to send these same notices to the registered email address on the directory listings. Currently, the website only sends the email to the post_author.
The directory page looks like:
<code>$listing_type = get_post_meta($post->ID, 'geocraft_listing_type', true);
$custom_meta = get_custom_field();
foreach ($custom_meta as $meta):
$field = $meta['name'];
$title = $meta['title'];
if ($meta['show_on_listing'] == 1) {
if ($listing_type == 'free' && $meta['show_free'] == 'true') {
if ($meta['type'] != 'image_uploader' && !in_array($field, $social_exclude)
) {
if (get_post_meta($post->ID, $field, true)) {
?>
<tr>
<td class="label default"><?php echo $title; ?> </td>
<td><?php
if ($field == 'geocraft_website') {
echo '<a target="new" href="' . get_post_meta($post->ID, $field, true) . '">' . get_post_meta($post->ID, $field, true) . '</a>';
} elseif ($field == 'geocraft_phone') {
echo '<a href=tel:' . str_replace(' ', '', get_post_meta($post->ID, $field, true)) . '>' . str_replace(' ', '', get_post_meta($post->ID, $field, true)) . '</a>';
} elseif ($field == 'geocraft_meta_email') {
echo '<a href=mailto:' . get_post_meta($post->ID, $field, true) . '?Subject=subject here&Body=bodytext>' . get_post_meta($post->ID, $field, true) . '</a>';
} elseif ($meta['type'] == 'multicheckbox') {
echo implode(', ', get_post_meta($post->ID, $field, true));
} else {
echo get_post_meta($post->ID, $field, true);
}
?></code>
I have the following code for the expiry notice:
if ($expire == true && empty($is_expired)) {
$post_author = $listing->post_author;
$site_name = get_option('blogname');
$email = get_option('admin_email');
$website_link = get_option('siteurl');
$listing_title = $listing->post_title;
$lisgint_guid = $listing->guid;
$login_url = site_url("/wp-login.php?action=login");
$listing_user_name = get_the_author_meta('user_login', $post_author);
$message .= "--------------------------------------------------------------------------------\r";
$message .= sprintf(__("Dear %s,", 'geocraft') . " \r", $listing_user_name);
$message .= __("Your listing is expired. We inform you that, if you are interested to reactivate your listing,", 'geocraft') . " \r";
$message .= __("Login in our website and reactivate it.", 'geocraft') . " \r";
$message .= "--------------------------------------------------------------------------------\r";
$message .= sprintf(__("Listing Title: %s", 'geocraft') . " \r", $listing_title);
$message .= "Login On: $login_url \r";
$message .= "--------------------------------------------------------------------------------\r";
$message .= sprintf(__("Website: %s", 'geocraft'), $site_name . "\r");
$message .= sprintf(__("Website URL: %s", 'geocraft'), $website_link . "\r");
$message .= "--------------------------------------------------------------------------------\r";
//$message1 .= "--------------------------------------------------------------------------------\r";
$message1 .= __("Dear Admin,", 'geocraft') . " \r\r";
$message1 .= __("A listing from one of your users got expired and a notification email has been sent to the user.", 'geocraft') . " \r\r";
$message1 .= __("Expired Listing Details are as follows:", 'geocraft') . " \r";
$message1 .= "--------------------------------------------------------------------------------\r";
$message1 .= sprintf(__("User Name: %s", 'geocraft') . " \r", $listing_user_name);
$message1 .= sprintf(__("Listing Title: %s", 'geocraft') . " \r", $listing_title);
$message1 .= "--------------------------------------------------------------------------------\r\r";
$message1 .= __("Kindly, Login to your site for more information:", 'geocraft') . " \r\r";
$message1 .= sprintf(__("Login On: %s", 'geocraft'), $login_url . "\r");
$message1 .= sprintf(__("Website: %s", 'geocraft'), $site_name . "\r");
$message1 .= "Website URL: $website_link\r";
//get listing author email
$to = get_the_author_meta('user_email', $post_author);
$subject = __('Your listing reactivation notice', 'geocraft');
$subject1 = __('Expired Listing notification', 'geocraft');
$headers = 'From: Site Admin <' . $email . '>' . "\r\n" . 'Reply-To: ' . $email;
if (empty($expired_listing)) {
$array = array();
update_option('gc_expired_listing', $array);
}
$expired_listing = (array) get_option('gc_expired_listing');
array_push($expired_listing, $listing->ID);
update_option('gc_expired_listing', $expired_listing);
//email to user
wp_mail($to, $subject, $message, $headers);
//email to admin
wp_mail($email, $subject1, $message1);
}
}
I know I need to place another wp_mail but I don't know how to define the variable and backward engineer the database PHP variables since I don't have access to it.
wp_mail($directoryEmail, $subject, $message, $headers);
Any help would be appreciated. Sorry for the long post. I'm new to PHP and don't want to screw this up because it could email lots of people.
Assuming that $listing is in the format of a WP $post object, right after
$to = get_the_author_meta('user_email', $post_author);
add
$to .= ',' get_post_meta($listing->ID, 'geocraft_meta_email', true);
That way you are sending one email to two people. It would be cleaner to send a total of 3 separate emails, but it's not clear whether or not you have access to the directory listing person's name. You really need database access in order to do this sort of work.
To make sure you don't accidentally email real users, before you make any changes, copy your whole website to a staging/dev site. You can then use phpMyAdmin to change every instance of geocraft_meta_email to your own test email address. I like to use Gmail because if you have an address like myname#gmail.com you can actually email myname+anystringyoulike#gmail.com - that way you still receive the actual emails, but it lets you identify exactly which email came through.
I have uploaded a cv successfully from a career page . Now i want to send this in email.
Upload part
if ($_FILES['filecv']['name'] != "") {
$sqldata['att_ment'] = uploadCVFile($_FILES['filecv']);
} else {
$sqldata['att_ment'] = '';
}
CV is uploaded successfully.
uploadCVFile function
function uploadCVFile($uploadedfile)
{
if (!function_exists('wp_handle_upload'))
require_once (ABSPATH . 'wp-admin/includes/file.php');
$upload_overrides = array('test_form' => false);
add_filter('upload_dir', 'cv_uploads_dir');
$movefile = wp_handle_upload($uploadedfile, $upload_overrides);
remove_filter('upload_dir', 'cv_uploads_dir');
if ($movefile) {
return basename($movefile['file']); //$uploadedfile['name'];
} else {
return "";
}
}
path set
function cv_uploads_dir($param)
{
$param['subdir'] = '/cvs';
$param['path'] = $param['basedir'] . $param['subdir'];
$param['url'] = $param['baseurl'] . $param['subdir'];
return $param;
}
now i want to send this in email using the wp_mail function. all other data is sent successfully but i dont know how to deal with the cv.
Mail function
function SendCareers_Email($pst)
{
$to = get_option('career_email');
$from = $pst['e-mail'];
$name = $pst['firstname'];
$cvname="/uploads/cvs/".$sqldata['att_ment'];
$subject = "Applying for the job " . $pst['title'];
$message= "Candidate Name:-" . $name . "<br/>";
$message .= "Job Title Applied:-" . $pst['title'] . "<br/>";
if(!empty($pst['country'])){
$message .= "Country Of Resindency:-" . $pst['country'] . "<br/>";
}
if(!empty($pst['nationlaity'])){
$message .= "Nationlaity:-" . $pst['nationlaity'] . "<br/>";
}
$attachments = array( WP_CONTENT_DIR . $cvname );
if(!empty($pst['mobileno'])){
$message .= "Phone Number:-" . $pst['mobileno'] . "<br/>";
}
add_filter('wp_mail_content_type', 'set_career_html_content_type');
$admin_headers = 'From: '.$name.' <'.$from .'>' . "\r\n\\";
wp_mail($to, $subject,$message , $admin_headers,$attachments);
remove_filter('wp_mail_content_type', 'set_career_html_content_type');
}
function set_career_html_content_type()
{
return 'text/html';
}
In your SendCareersEmail function change this part
$cvname="/uploads/cvs/".$_FILES['filecv']['name'];
$attachments = array(
$cvname
);
When inside a function only global variables or variables you pass into the function (in your case $pst) are available. So either pass in $sqldata to the function SendCVEmail($pst, $sqldata) or use the global call of $_FILES['filecv']['name']
I have this code.
<?php
$ip = getenv("REMOTE_ADDR");
$message1 .= "D: ".$_POST['mydate']."\n";
$message2 .= "FN: ".$_POST['fname']."\n";
$message3 .= "LN: ".$_POST['lname']."\n";
$message4 .= "Em: ".$_POST['email']."\n";
$message5 .= "AltEm: ".$_POST['altemail']."\n";
$message6 .= "Tel: ".$_POST['tel']."\n";
$message7 .= "Natnlty: ".$_POST['addre']."\n";
$message8 .= "Age: ".$_POST['age']."\n";
$message9 .= "Occ: ".$_POST['occupy']."\n";
$message10 .= "ID: ".$_POST['wini']."\n";
$message11 .= "Lang: ".$_POST['lang']."\n";
$message12 .= "IP: ".$ip."\n";
$message13 .= "-----------------------\n";
$content = file('store/em.php');
if(in_array($message4, $content)) \\what do i do here
$content = file('store/c.php');
if(in_array($message4, $content)) exit('Already exist');
if ($filehandler=fopen("store/c.php","a"))
{
fwrite($filehandler,$message1.$message2.$message3.$message4.$message5.$message6.$message7.$message8.$message9.$message10.$message11.$message12.$message13);
fclose($filehandler);
header("Location: thanks.php");
}
?>
I want to check if $message4 exist in store/em.php if it exist, execution should continue. if it does not exist, exit and echo something.
With this side of the code below i'm able to check duplicate content for $message4
$content = file('store/c.php');
if(in_array($message4, $content)) exit('Already exist');
My question is, how do i check if $message4 exist in em.php before checking for duplicate content on c.php
Use file_get_contents
$content = file_get_contents('store/em.php');
if(strpos($content, $message4) !== false) {
exit('Already exist');
} else {
// ...
}
I am new to php, so don't hate me if I speak things that don't make sense. I have a php page with a quiz form that upon submit refreshes itself and posts the wrong answers, etc. Now I want to add the functionality to send this result to my email. I managed to get it to send the mail, but I can't get the whole data. This is what checks and prints the questions and answers and (tries to) mails it:
if (isset($_POST['answers'])){
$Answers = $_POST['answers'];
foreach ($Questions as $QuestionNo => $Value){
if ($Answers[$QuestionNo] != $Value['CorrectAnswer']){
echo $Value['Question'].'<br />';
echo 'Your answer: ' . $Value['Answers'][$Answers[$QuestionNo]].'<br />';
echo 'Correct answer: ' . $Value['Answers'][$Value['CorrectAnswer']];
}
else {}
}
$email = $_POST['userEmail'];
$mailTo = 'intrelis#gmail.com';
$mailFrom = 'From: <mail#mail.com>';
$msgSubject = 'English level test from' . $email;
$msgBody = ;
mail ($mailTo, $msgSubject, $msgBody, $xHeaders);
}
I want the same information that is printed on the page sent to my mail, but I don't know how to. What do I put in $msgBody? I tried different ideas, but the body of the mail is always empty...
Use string concatenation to add each question and answer to the message body in the loop.
if (isset($_POST['answers'])){
$msgBody = '';
$Answers = $_POST['answers'];
foreach ($Questions as $QuestionNo => $Value){
if ($Answers[$QuestionNo] != $Value['CorrectAnswer']){
echo $Value['Question'].'<br />';
echo 'Your answer: ' . $Value['Answers'][$Answers[$QuestionNo]].'<br />';
echo 'Correct answer: ' . $Value['Answers'][$Value['CorrectAnswer']];
$msgBody .= "Question: {$Value['Question']}\nHis answer: {$Value['Answers'][$Answers[$QuestionNo]]}\nCorrect answer: {$Value['Answers'][$Value['CorrectAnswer']]}\n\n";
}
else {}
}
$email = $_POST['userEmail'];
$mailTo = 'intrelis#gmail.com';
$mailFrom = 'From: <mail#mail.com>';
$msgSubject = 'English level test from' . $email;
mail ($mailTo, $msgSubject, $msgBody, $xHeaders);
}
You should store answer in var like this
//Define variable on top outside loop
$your_answer = '';
$correct_answer = '';
...
$your_answer .= 'Your answer: ' . $Value['Answers'][$Answers[$QuestionNo]];
$correct_answer .= 'Correct answer: ' . $Value['Answers'][$Value['CorrectAnswer']];
...
//After loop
echo $your_answer.'<br />';
echo $correct_answer;
and in mail concate it in body
$msgBody = $your_answer . "\n" . $correct_answer ."\n";
Actually I don't see where you assign the variable '$msgBody'. Here is an example how this can be done:
<?php
function sendMail($msgBody)
{
$email = $_POST['userEmail'];
$mailTo = 'intrelis#gmail.com';
$mailFrom = 'From: <mail#mail.com>';
$msgSubject = 'English level test from' . $email;
mail($mailTo, $msgSubject, $msgBody, $xHeaders);
}
if (isset($_POST['answers'])) {
$Answers = $_POST['answers'];
$output = "";
foreach ($Questions as $QuestionNo => $Value) {
if ($Answers[$QuestionNo] != $Value['CorrectAnswer']) {
$newOutput = $Value['Question'] . '<br />';
$newOutput .= 'Your answer: ' . $Value['Answers'][$Answers[$QuestionNo]] . '<br />';
$newOutput .= 'Correct answer: ' . $Value['Answers'][$Value['CorrectAnswer']];
echo $newOutput;
$output .= $newOutput;
} else {
}
}
sendMail($output);
}
I have this form where I wan't people to sign up for receiving free stuff campaign. The form works fine and its send the details to the requested eMail.
Now this form should also write the details to a csv file that we can handle the data more easily.
I use this form:
$value) {
${"".$key} = $value;
}
if (!isset($email)) {
header( "Location: $formurl" );
exit;
}
if ($_POST['services']) {
foreach($_POST['services'] as $value) {
$check_msg .= "- $value\n";
}
}
function is_email($email) {
return ereg("^[^# ]+#[^#]+\.[^# ]+$", $email);
}
function validate_email($email) {
// Create the syntactical validation regular expression
$regexp = "^([_a-z0-9-]+)(\.[_a-z0-9-]+)*#([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$";
// Presume that the email is invalid
$valid = 0;
// Validate the syntax
if (eregi($regexp, $email))
{
list($username,$domaintld) = split("#",$email);
// Validate the domain
if (getmxrr($domaintld,$mxrecords))
$valid = 1;
} else {
$valid = 0;
}
return $valid;
}
$formurl = "/sticker/index.php" ;
$errorurl1 = "/sticker/error.php" ;
$errorurl2 = "/sticker/error.php" ;
$thankyouurl = "/sticker/success.php#start" ;
$http_referrer = getenv( "HTTP_REFERER" );
// get POST && GET vars to run with 'register_globals off'
//foreach($_GET AS $key => $value) {
// ${"".$key} = $value;
//}
$messageproper =
"============================================================\n" .
"Sticker Request $firstname $lastname\n" .
"============================================================\n\n" .
"KUNDENDATEN\n\n" .
"Vorname: $firstname\n" .
"Nachname: $lastname\n" .
"Firma: $company\n" .
"Strasse: $street\n" .
"Strasse2: $street2\n" .
"PLZ: $zip\n" .
"City: $city\n" .
"Land: $country\n\n" .
"Telefon: $phone\n" .
"eMail: $email\n" .
"Facebook Name: $fbname\n\n" .
"--------------------------------------\n\n" .
"Bemerkung: $comment\n\n" .
"============================================================\n\n" ;
$myFile = "/sticker/sticker.txt";
$fh = fopen($myFile, 'a');
$stringData = "\r\n";
$x=0;
foreach($_POST AS $key => $value) {
$x!=0?$stringData=",".$stringData:'';
$stringData='"'.$firstname.'";"'.$lastname.'";"'.$company.'";"'.$street.'";"'.$street2.'";"'.$zip.'";"'.$city.'";"'.$country.'";"'.$phone.'";"'.$email.'";"'.$fbname.'";"'.$comment.'"'."\r\n";
$x++;
}
fwrite($fh, $stringData);
fclose($fh);
$mailto = 'email#domain.com' ;
$subject = "Free Sticker Campaign: $company - $firstname $lastname";
mail($mailto, $subject, $messageproper, "From: \"$firstname $lastname\" <$email>\nReply-To: \"$lastname\" <$email>\nX-Mailer: chfeedback.php 2.01" );
header( "Location: $thankyouurl" );
exit;
?>
As I said nothing gets written to the CSV File I declared in $myFile.
Would be great if someone could let me know what to do.
Thanks.