I tried this code from the post, but this code is sending two emails on a single run of file.
Email file is sending email two times using php mail function
Let me know what i am doing wrong -
<?php
function mytextoverimage( $mytext ) {
$headurl = 'http://dummyimage.com/600x400/ffffee/00d5ff.jpg';
header('Content-type: image/jpeg');
$jpg_image = imagecreatefromjpeg($headurl);
$black = imagecolorallocate($jpg_image, 1, 1, 1);
$font_path = 'myfont/arial.ttf';
$text = $mytext;
imagettftext($jpg_image, 24, 0, 175, 85, $black, $font_path, $text);
imagejpeg($jpg_image);
imagedestroy($jpg_image);
}
$to = "myemail#gmail.com";
$subject = "This is a image conversion from Developer Zone";
$headers = "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= 'From: developer#phpdev.com' . "\r\n" .
'Reply-To: testabc#testabc.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$message = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My Title</title>
</head>
<body>
<table width="100%" cellspacing="5" cellpadding="0" border="0" bgcolor="#f0f0f0" style="color:666666;text-align:left; font:12px Verdana, Geneva, sans-serif">
<tr>
<td >'.mytextoverimage('Developer').'</td></tr></table></body></html>';
mail($to,$subject,$message,$headers); die;
Let me know what i am doing wrong, is this the correct method I am using this --
<img src="'.mytextoverimage('Developer').'" />
I followed this URL but hard to crack any help from this page- http://php.net/manual/en/function.imagejpeg.php
I even tried keeping that method mytextoverimage() in another file but still no help, email sending twice :(
Your mytextoverimage() function doesn't return anything - it just sends a jpeg image to the browser.
I've reworked your code to send the same image via email - note that just the image is sent, no HMTL.
If you want to send an image as part of an HTML document, you need to go a step further and create a multipart message - check out How to attach and show image in mail using php?
This works for Gmail on Iceweasel 10.0.11.
<?php
function mytextoverimage( $mytext )
{
$headurl = 'http://dummyimage.com/600x400/ffffee/00d5ff.jpg';
$jpg_image = imagecreatefromjpeg($headurl);
$black = imagecolorallocate($jpg_image, 1, 1, 1);
$font_path = 'myfont/arial.ttf';
$text = $mytext;
imagettftext($jpg_image, 24, 0, 175, 85, $black, $font_path, $text);
ob_start(); //Get the image data from the output buffer
imagejpeg($jpg_image);
imagedestroy($jpg_image);
return chunk_split(base64_encode(ob_get_clean())); //return the image data, encoded for email transfer
}
$to = "myemail#gmail.com";
$subject = "This is a image conversion from Developer Zone";
// --- Note the change from text/html to image/jpeg ---
$headers = "Content-type: image/jpeg;\r\n";
//$headers = "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= 'From: developer#phpdev.com' . "\r\n" .
'Reply-To: testabc#testabc.com' . "\r\n" .
'Content-Transfer-Encoding: base64' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$message = mytextoverimage('Developer');
mail($to,$subject,$message,$headers); die;
Yes you are doing it wrong. Imagejpg function returns and image, but you need a url to put it inside a tag. What you should do is use SWIFT mailer and send that image you created as ann attachment to the email.
you can read on it here:
http://swiftmailer.org/docs/messages.html
It would belike this:
//Create the message
$img = $message->embed(Swift_Image::fromPath('body1.jpg'));
//Set the body
$message->setBody(
'<html>' .
' <head></head>' .
' <body>' .
" <img src='$img'/>"
' </body>' .
'</html>',
'text/html' //Mark the content-type as HTML
);
As per as my question was concerned I solved it, like in this way -
<?php
function myimagecreate( $name )
{
$headurl = 'http://dummyimage.com/600x300/f5ebf5/f2f2f7.jpg';
header('Content-type: image/jpeg');
$text = $name;
$name =$name.".jpg";
$filepath = 'http://MY_SITE_URL.com/'."myfont";
$jpg_image = imagecreatefromjpeg($headurl);
$black = imagecolorallocate($jpg_image, 1, 1, 1);
$font_path = 'myfont/Ayuma2yk.ttf';
imagettftext($jpg_image, 24, 0, 175, 85, $black, $font_path, $text);
imagejpeg($jpg_image,$name);
imagedestroy($jpg_image);
return $name;
}
$to = 'YOUREMAIL#gmail.com';
$subject = 'Swapnesh Sinha - For PHP GD Library';
$message = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Swapnesh Sinha</title>
</head>
<body>
<table width="600px" bgcolor="#f0f0f0" style="color:666666;text-align:left; font:12px Verdana, Geneva, sans-serif">
<tr>
<td>
<img src="http://MY_SITE_URL.com/'.myimagecreate('Swapnesh').'" style="display:block" />
</td>
</tr>
</table>
</body>
</html>';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Swapnesh Sinha <MyMAIL#gmail.com>'. "\r\n";
$bool = mail($to,$subject,$message,$headers);
if($bool)
echo "Email is sent successfully";
else
echo "Something is missing in the code, please check the code properly!!";
?>
Just save the code in any root file "Yourfile.php" and run.
This will create an image and save to root location(you can force to save it another location also).
Follow these two links as well -
LINK 1
LINK 2
Related
So far bcrypt has had no problems until now. For some reason the following password won't work. UIO78349%^&(]\\';= This is the first time I've had a password not work and I hope somebody has an explanation. I hunted the net and read about the character limit but this is well below that. Not sure if it makes any difference but the user input for password is going through mysqli_real_escape_string.
First batch of code where the login form is located:
<?php
session_start();
?>
<html>
<body>
<form method="post" action="sidebar-signin-block.php">
<table width="90%" border="0" align="center" bgcolor="white">
<tr>
<td bgcolor="ffffff" colspan="2" align="center"><h2>User Login</h2></td>
</tr>
<tr>
<td align="right">Email:</td>
<td><input type="text" name="email"></td>
</tr>
<tr>
<td align="right">Password:</td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="login" value="Login"></td>
</tr>
<tr>
<td colspan="2" align="center"><h3 style="margin-top:7px;">Forgot Password?</h3></td>
</tr>
<tr>
<td bgcolor="#ffffff" colspan="2" align="center"><div style="padding-top:5px;"><span style="font-size:20px;">Don't have an account?<br />Sign Up is <em>quick</em> and <em>easy</em>!</span></div></td>
</table>
</form>
<?php
// Connecting to the database and making the Bcrypt functions available
include("admin/includes/connect.php");
include ("lib/password.php");
// Gathering and sanitizing user login input
if(isset($_POST['login'])){
$email = trim(((isset($conn) && is_object($conn)) ? mysqli_real_escape_string($conn, $_POST['email']) :((trigger_error ("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : "")));
$pass = trim(((isset($conn) && is_object($conn)) ? mysqli_real_escape_string($conn, $_POST['password']) : ((trigger_error ("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : "")));
// Checking the database records for the user login input
$hash_query = "select nonadmin_user_pass from nonadmin_user_login where email='$email'";{
$run_query = mysqli_query($conn, $hash_query);}
while ($row = mysqli_fetch_assoc($run_query)) {
$fetch_pass = $row['nonadmin_user_pass'];
}
// If the user email and password matches we start a session
if ((password_verify($pass, $fetch_pass)) == 1){
// Verifying user login success with splash page then sending user back to the home page
$_SESSION['email']=$email;
echo "<script>window.open('login-success.php','_self')</script>";}
// When the user login fails an alert is given to inform them
else {
echo "<script>alert('Email or password is incorrect please try again')</script>";
echo "<script>window.open('index.php','_self')</script>";}
}
?>
</body>
</html>
Here the js.
<script>$(document).ready(function(){
$("#login").click(function(){
var email = $("#email").val();
var password = $("#password").val();
// Checking for blank fields.
if( email =='' || password ==''){
$('input[type="text"],input[type="password"]');
$('input[type="text"],input[type="password"]');
alert("Please fill all fields.");
}else {
$.post("log-me-in.php",{ email1: email, password1:password},
function(data) {
if(data=='Invalid Email.......') {
$('input[type="text"]');
$('input[type="password"]');
alert(data);
}else if(data=='Email or Password is wrong please try again.'){
$('input[type="text"],input[type="password"]');
alert(data);
} else if(data=='Successfully Logged in.'){
window.location.reload();
$("form")[0].reset();
$('input[type="text"],input[type="password"]');
alert(data);
} else{
alert(data);
}
});
}
});
});</script>
Here's the php being called:
<?php
session_start();
// Connecting to the database and making the Bcrypt functions available
include("admin/includes/connect.php");
include ("lib/password.php");
$email=$_POST['email1']; // Fetching Values from URL.
$password= ($_POST['password1']);
// check if e-mail address syntax is valid or not
//$email = filter_var($email, FILTER_SANITIZE_EMAIL); // sanitizing email(Remove unexpected symbol like <,>,?,#,!, etc.)
//if (!filter_var($email, FILTER_VALIDATE_EMAIL)){
//echo "Invalid Email.......";
//}else{
// Matching user input email and password with stored email and password in database.
$result = mysqli_query($conn, "SELECT * FROM nonadmin_user_login WHERE email='$email'");
$data = mysqli_fetch_array($result);
$bcrypt_pass = $data['nonadmin_user_pass'];
$email_match = $data['email'];
if (password_verify ($password, $bcrypt_pass) == 1 AND $email == $email_match) {
$_SESSION['email']=$email;
echo "Successfully Logged in.";
}
else{
echo "Email or Password is wrong please try again";
}
//}
?>
Here is the user registration code where the password initially gets entered before mail verification:
<html>
<head>
<title>Register at Recycling Kansas City</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="/styles/register-user.css" media="all">
<!-- ie compatibility -->
<!--[if IE]>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<![endif]-->
<!--[if lt IE 9]>
<script src="Site/javascript/bootstrap/html5shiv.js"></script>
<![endif]-->
<meta content="recycling kansas city, recycling centers, recycling locations" name="keywords">
<meta content="Recycling Kansas City is an efficient resource to help you quickly find a recycle center that is nearby. Use our map to find locations and accepted items." name="description">
</head>
<h1 class="center">Why register at Recycling Kansas City?</h1>
<p>By registering here you will gain access to additional features. Once registered you can create your own custom profile, submit and comment on blog articles, advertise your products or services and have the choice to opt in for email announcements.</p>
<p>All of your information will be securely stored in our database and you can delete your account at any time. Also, rest assured that we will never share any of your submitted details with anyone ever.</p>
<form method="post" action="register-user.php">
<table width="520" border="10" align="center" bgcolor="white">
<tr>
<td bgcolor="ffffff" colspan="2" align="center"><h1>Registration</h1></td>
</tr>
<tr>
<td align="right">Email</td>
<td><input type="text" name="email" size="53"></td>
</tr>
<tr>
<td align="right">Password:</td>
<td><input type="password" name="pwd" size="53"></td>
</tr>
<tr>
<td align="right">User Name:</td>
<td><input type="text" name="name" size="53"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="register" value="Register"></td>
</tr>
</table>
</form>
</html>
<?php
include ("../admin/includes/connect.php");
include ("../lib/password.php");
$con = new mysqli("localhost", "$username", "$password", "$database");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
if(isset($_POST['register'])){
$email = trim(mysql_escape_string($_POST['email']));
$nonadmin_user_pass = trim(mysql_escape_string($_POST['pwd']));
$password = password_hash($nonadmin_user_pass, PASSWORD_BCRYPT);
$nonadmin_user_name = trim(mysql_escape_string($_POST['name']));
$query_verify_email = "SELECT * FROM nonadmin_user_login WHERE email ='$email' and verified = 1";
$verified_email = mysqli_query($con,$query_verify_email);
if (!$verified_email) {
echo ' System Error';
}
if (mysqli_num_rows($verified_email) == 0) {
// Generate a unique code:
$hash = md5(uniqid(rand(), true));
$query_create_user = "INSERT INTO `nonadmin_user_login` (`email`, `nonadmin_user_pass`, `nonadmin_user_name`, `hash`) VALUES ('$email', '$password', '$nonadmin_user_name', '$hash')";
$created_user = mysqli_query($con,$query_create_user);
if (!$created_user) {
echo 'Query Failed ';
}
if (mysqli_affected_rows($con) == 1) { //If the Insert Query was successfull.
$subject = 'Activate Your Email';
$headers = "From: admin#recyclingkansascity.com \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$url= 'http://recyclingkansascity.com/includes/register-verify.php?email=' . urlencode($email) . "&key=$hash";
$message ='<p>To activate your account please click on Activate buttton</p>';
$message.='<table cellspacing="0" cellpadding="0"> <tr>';
$message .= '<td align="center" width="300" height="40" bgcolor="#000091" style="-webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px;
color: #ffffff; display: block;">';
$message .= '<a href="'.$url.'" style="color: #ffffff; font-size:16px; font-weight: bold; font-family: Helvetica, Arial, sans-serif; text-decoration: none;
line-height:40px; width:100%; display:inline-block">Click to Activate</a>';
$message .= '</td> </tr> </table>';
mail($email, $subject, $message, $headers);
echo '<p class="center">A confirmation email
has been sent to <b>'. $email.' </b></p><p class="center">Please <strong>click</strong> on the <strong><em>Activate</em> Button</strong> to Activate your account.</p> ';
} else { // If it did not run OK.
echo '<div>You could not be registered due to a system
error. We apologize for any
inconvenience.</div>';
}
}
else{
echo '<div>Email already registered</div>';}
}
?>
So far never a hiccup on any password until the password at the top of the post? Weird if you ask me.
Remove all calls to mysqli_real_escape_string() for password input, the functions password_hash() and password_verify() accept even binary input and are not prone to SQL-injection. I assume this already solves your problem. Escaping should be done as late as possible and only for the given target system, so the function mysqli_real_escape_string() should only be called to build an SQL query.
Then the function password_verify() already returns a boolean, no need to compare it with == 1.
if (password_verify($pass, $fetch_pass))
{
...
}
If this doesn't solve your problem, i would make sure that every page uses UTF-8 as file format and defined it in the header.
I have placed the following code in joomla 2.5
<?php
$app = JFactory::getApplication();
$menu = $app->getMenu()->getActive();
$pageclass = '';
if (is_object($menu))
$pageclass = $menu->params->get('pageclass_sfx');
?>
<body id="<?php echo $pageclass ? htmlspecialchars($pageclass) : 'default'; ?>">
But it's getting default for all pages.
Ooops! its resulting this
<body default""="" style="font-size: 100%;">
I take alias to make different id for each page
<body id="<?php echo (isset($menu) || !empty($menu))?$menu->alias:'default'; ?>">
And working fine.
My three concerns, tried different combos with no result, googled but little or no help --
I received two times the email,change myemail#emailserver.com to the email id to see the result.
While executing this file I am getting image, however I want to have text "Email Sent".
Full HTML content with tag is passed instead of HTML rendering in email.
My Working Code -->
<?php
header('Content-type: image/jpeg');
$jpg_image = imagecreatefromjpeg('http://dummyimage.com/600x400/f5f5f5/fff.jpg');
$black = imagecolorallocate($jpg_image, 1, 1, 1);
$font_path = 'myfont/arial.ttf';
$text = "Swapnesh Sinha!";
imagettftext($jpg_image, 24, 0, 175, 85, $black, $font_path, $text);
$tip = imagejpeg($jpg_image);
$imageData = base64_encode($tip);
//$src = 'data: '.mime_content_type($jpg_image).';base64,'.$imageData;
imagedestroy($jpg_image);
?>
<html>
<head></head>
<body>
<p>
<?php
$to = 'myemail#emailserver.com';
$subject = "Thisa is a email test to find image work";
$message = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>MY SITE TITLE</title>
</head><body><table><tr><td>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</td></tr><tr><img src="'.'http://mysiteurl/addtext.php'.'" /></tr></table></body></html>';
$headers = 'From: myemail#emailserver.com' . "\r\n" .
'Reply-To: myemail#emailserver.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$bool = mail($to, $subject, $message, $headers);
if($bool)
echo "Email Sent";
else
echo "Email Not Sent";
?>
</body>
</html>
NOTE - In <img src="'.'http://mysiteurl/addtext.php'.'" />
http://mysiteurl/addtext.php is the same where we have all this above content.
First thing I'd do is check your apache/IIS logs to ensure that the URL isn't being called twice (just a sanity check).
If the PHP page you've added to your OP is http://mysiteurl/addtext.php, then it would be called twice, once renderering the HTML, then the browser would call it again when rendering the <img ...> tag.
To fix this you need to either split it into two PHP files (recommended), or pass a GET parameter to toggle the image processing.
You'll also need to add $headers .= "Content-type: text/html\r\n"; so that the email is rendered as html and not plain text.
I'm using this to generate a list of sub-pages that are a parent of 10 and images:
<ul>
<?php wp_list_pages('title_li=&child_of=10&link_after=<img src="http://mydomain.com/image.gif" alt="" />'); ?>
</ul>
It works, but the problem is I don't know how to get the post featured image there instead. I tried this but it did not work:
<?php wp_list_pages('title_li=&child_of=10&link_after=<img src="' . the_post_thumbnail(array(100,50)) . '" alt="" />'); ?>
Obviously I'm missing something.
Any suggestions would be appreciated.
To display the page titles along with the images, you should use get_pages()
<?php
$pages = get_pages('child_of=10');
if ($pages) {
echo '<ul>';
foreach ($pages as $page) {
echo '<li><a href="'.get_permalink($page->ID).'">';
echo get_the_title($page->ID);
echo get_the_post_thumbnail($page->ID);
echo '</a></li>';
}
echo '</ul>';
}
?>
The get_the_post_thumbnail function returns HTML not the image url.
Instead use
<?php $image_url = wp_get_attachment_image_src( get_post_thumbnail_id(10), array(100,50) ); ?>
<?php wp_list_pages('title_li=&child_of=10&link_after=<img src="' . $image_url . '" alt="" />'); ?>
This will list all sub-pages of page id 10, with thumbnail of page id 10. If you want the thumbnails of the sub-pages instead of parent page, you will have to write custom code instead of wp_list_pages function(as explained by Indranil).
i am using codeigniter . in my form i am using a captcha . all worked fine ,but now it is not loading , when i checked in firebug this error gives
Image corrupt or truncated: http://localhost/elephanti//home/auth/get_capture/913472
this is my controller
function get_capture() {
$this->auth_lib->get_capture_image ();
}
in my view
<div
class="form-item">
<div class="catergory-inputs">
<div class="textarea-large-container" id="caption">
<img border="0"
src="<?php echo $this->config->item('base_url'); ?>/home/auth/get_capture/<?php echo rand();?>"
id="captcha" width="225" height="67" />
</div>
<div class="caption-icon">
<img
src="<?php echo $this->config->item('img_path') ?>/icon-caption.png"
width="19" height="20" alt="icon-caption"
style="cursor: pointer;"
onclick="reload_chaptca('<?php echo $this->config->item('base_url'); ?>/home/auth/get_capture/','<?php echo rand();?>')" />
</div>
</div>
</div>
in my aut_lib
public function get_capture_image()
{
$this->ci->load->model('captcha/captcha_model');
$path = APPPATH . '../../assets/3rd/captcha';
$this->ci->captcha_model->lmj_crate_image($path);
}
this is my captcha model
public function lmj_crate_image($path) {
$this->resourcesPath=$path;
$ini = microtime(true);
/** Initialization */
$this->lmj_reserved_image();
/** Text insertion */
$text = $this->lmj_get_the_captcha();
$fontcfg = $this->fonts[array_rand($this->fonts)];
$this->lmj_write_fonts($text, $fontcfg);
$this->session->set_userdata($this->session_var, $text);
// $_SESSION[$this->session_var] = $text;
/** Transformations */
$this->lmj_render_image();
if ($this->blur && function_exists('imagefilter')) {
imagefilter($this->im, IMG_FILTER_GAUSSIAN_BLUR);
}
$this->lmj_low_resalution();
if ($this->debug) {
imagestring($this->im, 1, 1, $this->height - 8,
"$text {$fontcfg['font']} " . round((microtime(true) - $ini) * 1000) . "ms",
$this->GdFgColor
);
}
/** Output */
$this->lmj_make_image_from_text();
$this->lmj_default_clean();
}
i can not figure out what is the problem here . this code may not be helpful .
if this is not helpful can you tell me possible reasons for not working this . thanks...........
http://blog.grahamlicence.co.uk/post/preventing-image-corrupt-or-truncated-error-in-firebug.aspx
Have you renamed an image's file extension (changed .jpg to .png for example) at all?
actually the issue was i had a white space in one of my libraries , after i removed the white space and removed the php closing tag , now it works correctly , thanks :)