One string PHP Content Type and HTML in Message fields - content-type

I am trying to add an image into my body for a php email. However I am having difficulty adding in the content type and making this work. Is it because I am refusing to have multiple $header = and $header .= lines?
Can't you add all of this code into one line of php script with . "\r\n" .
?
$emailthisbody = ' \n\n Message Line 1. \n\n Name: $emailthisname \n\nEmail: $emailthisemail \n\nProperty: $emailthiscomments ';
$header = 'From: '.$sitename.' <'.$emailTo1.'>' . "\r\n" . 'Reply-To: ' . $email . "\r\n" . 'MIME-Version: 1.0\r\n' . 'Content-Type: text/html; charset=ISO-8859-1\r\n';

if this is your actual code:
$header = 'From: '.$sitename.' <'.$emailTo1.'>' . "\r\n" . 'Reply-To: ' . $email . "\r\n" . 'MIME-Version: 1.0\r\n' . 'Content-Type: text/html; charset=ISO-8859-1\r\n';
Then I might see your problem. You have a literal backslash r backslash n in 2 places. Try this,
$header = 'From: '.$sitename.' <'.$emailTo1.'>' . "\r\n" . 'Reply-To: ' . $email . "\r\n" . 'MIME-Version: 1.0'."\r\n" . 'Content-Type: text/html; charset=ISO-8859-1'."\r\n";
and see if it works.

I find the php mail function to be a bit clunky in that you really have to know how to format a raw email.
I highly recommend using the PHPMailer library for sending anything other than the simplest of emails. Another popular mailing library would be Swift Mailer. Both will allow you to do what you are attempting in a much simpler way and you should be able to find plenty of documentation and tutorials online as they are both fairly widely adopted.

Related

HTML link not working in wp mail

I have set a wp mail function and on the body there is a link like
$to = $email;
$subject = "Payment Receipt - ".$fname.' '.$lname.' - '.date("m-d-Y");
$bodyadmin = "<html><head><title></title></head><body>Thank you for your
payment please click <a href='https://www.google.com/'>Here</a></body>
</html>";
$headersadmin = 'MIME-Version: 1.0' . "\r\n";
$headersadmin .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headersadmin .= 'From: ABC <abc#abc.com>' . "\r\n";
$headersadmin .= 'Cc: abc#abc.com' . "\r\n";
wp_mail( $to, $subject, $bodyadmin, $headersadmin );
But when i am trying to send mail the mail is not going. Can anyone please advise me why it is not working?
Try changing your body to
$bodyadmin = "<h3>Thank you for your
payment please click <a href='https://www.google.com/'>Here</a></h3>";
And it is good to use array type for headers as it will improve the clarity of your code and make it less error prone. For eg.
$headers[] = 'From: Me Myself <me#example.net>';
$headers[] = 'Cc: John Q Codex <jqc#wordpress.org>';
$headers[] = 'Cc: iluvwp#wordpress.org'; // note you can just use a simple email address
You can try following Example and try it:
$to = 'sendto#example.com';
$subject = 'The subject';
$body = 'The email body content';
$headers = array('Content-Type: text/html; charset=UTF-8');
wp_mail( $to, $subject, $body, $headers );
I don't see any error in code and it does work on my side. (screenshots available below for reference)
Problem:
The SMTP is not configured for your wordpress site. Please try any plugin to configure SMTP OR follow this tutorial.
Code:
Mailbox:
you have concatenation bug in your code, use this
$to = $email;
$subject = "Payment Receipt - ".$fname." ".$lname." - ".date('m-d-Y');
$bodyadmin = "<html><head><title></title></head><body>Thank you for your
payment please click <a href='https://www.google.com/'>Here</a></body>
</html>";
$headersadmin = 'MIME-Version: 1.0' . "\r\n";
$headersadmin .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headersadmin .= 'From: ABC <abc#abc.com>' . "\r\n";
$headersadmin .= 'Cc: abc#abc.com' . "\r\n";
wp_mail( $to, $subject, $bodyadmin, $headersadmin );

having issues with this simple code trying to get a value

am just confused why such a small difference can make a big problem.
here is the working code with just digits entered into it.
$user_info = get_userdata(70);
echo 'Username: ' . $user_info->user_login . "\n";
this code shows username: sarah
and now same but this time with code inside of it
$number = the_author_meta('ID');
echo $number; // echos 70
$user_info = get_userdata($number);
echo 'Username: ' . $user_info->user_login . "\n";
and with the code below it just shows userame: thats it.
MAke sure you read your code. At this line:
$user_info = get_userdata($number);
You miss a r in the variable $number
Here's the problem:
Replace "the_author_meta" with "get_the_author_meta"
the_author_meta just immediately outputs to the screen the information you're trying to retrieve. That's why it outputs '70'.. If you get rid of the echo in front of it, it'd STILL output that 70.
get_the_author_meta actually returns the value and assigns it to a variable, like you're expecting.
$aaaaaa = $author_id=$post->post_author;
$user_info = get_userdata($aaaaaa);
echo 'Username: ' . $user_info->user_login . "\n";
echo 'User roles: ' . implode(', ', $user_info->roles) . "\n";
echo 'User ID: ' . $user_info->ID . "\n";
echo get_user_option( 'rc_banned', $user_info->ID);

Bcc: using custom Wordpress mail.php contact form

I'm attempting to have a custom contact form within our Wordpress site send a Bcc to me when it sends the completed form to the recipient. The $headers section of the form looks like this:
$headers = 'Content-type: text/html; charset=iso-8859-1'."\r\n";
$headers .= 'From: '.$email;
I have tried to achieve a Bcc using this:
$headers = 'Content-type: text/html; charset=iso-8859-1'."\r\n";
$headers .= 'From: '.$email;
$headers .= 'Bcc: '.myemail#email.com;
...but it only sends to the standard recipient, not the Bcc address.
Can you see what I'm doing wrong? Many thanks!
Try the array form of $headers -
$headers[] = 'Content-type: text/html; charset=iso-8859-1';
$headers[] = 'From: '.$email;
$headers[] = 'Bcc: myemail#email.com';

Google Analytics API: problems extracting some data

How do I use this API? I can extract some data, but not all of it... I'm a bit lost and I can't find any examples in the documentation. I'm using gapi.class.php.
I have code such as:
$ga = new gapi('user','pwd');
$ga->requestReportData('id',array('browser'),array('pageviews','visits', 'timeOnSite'));
var_dump($ga);
foreach($ga->getResults() as $result)
{
print_r($result);
echo '<strong>'.$result.'</strong><br />';
echo 'Pageviews: ' . $result->getPageviews() . ' ';
echo 'Visits: ' . $result->getVisits() . '<br />';
echo 'Time On site: ' . $result->getTimeOnSite() . '<br />';
}
echo '<p>Total pageviews: ' . $ga->getPageviews() . ' total visits: ' . $ga->getVisits() . '</p>';
The above is working, but then I also want to get other data such as goals... I see this: http://code.google.com/intl/es-ES/apis/analytics/docs/gdata/dimsmets/dimsmets.html
but I'm not really sure how to call each function, or property... I'm really lost, any examples would be appreciated!
GAPI uses magic get methods. You put in the dimensions and metrics that you want and get them using the magic get methods.
For example:
$ga = new gapi('user','pwd');
$ga->requestReportData('id',array('browser'),array('pageviews','visits', 'timeOnSite'));
foreach($ga->getResults() as $result)
{
print_r($result);
echo '<strong>'.$result.'</strong><br />';
echo 'Pageviews: ' . $result->getPageviews() . ' ';
echo 'Visits: ' . $result->getVisits() . '<br />';
echo 'Time On site: ' . $result->getTimeOnSite() . '<br />';
}
echo '<p>Total pageviews: ' . $ga->getPageviews() . ' total visits: ' . $ga->getVisits() . '</p>';
array('browser') is the dimension and array('pageviews','visits', 'timeOnSite') are the metrics. $result->getPageviews() is the magic get method for the pageviews metric.
So, refer to the list and put in the dimensions and metrics you want then return them using the magic get methods of getYourdimension or getYourmetric. Note that get is lowercase and the dimension or metric begins with a capital letter.
See the documentation for more information:
Access metrics and dimensions using magic get methods
With GAPI, when data is returned from Google it is automatically converted into a native PHP object, with an interface to allow the 'get' the value of any dimesion or metric.
For example, if you request the metric 'uniquePageviews' and the dimesion 'pagePath' you can do the following:
foreach($ga->getResults() as $result)
{
echo $result->getUniquePageviews();
echo $result->getPagePath();
}

disable comment rss

i am using this to automatic display the rss in the header.php
automatic_feed_links();
in the header appears feed=rss2 and feed=comments-rss2
now i just want to disable the comments-rss2 since i dont use comments in the theme.
if i use remove_action( 'wp_head', 'feed_links', 2 ); both are removed from the head.
I just want to remove the comments-rss2 -
couldnt find any reference how to this.
anyone know?
feed_links function in wp-includes/general-template.php contains echo command for both feed and not be able to disable with argument. Comment out // this line: (wp-includes/general-template.php #1614 for wp3.1)
echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr(sprintf( $args['comstitle'], get_bloginfo('name'), $args['separator'] )) . '" href="' . get_feed_link( 'comments_' . get_default_feed() ) . "\" />\n";

Resources