Showing posts with label send. Show all posts
Showing posts with label send. Show all posts

Wednesday, June 8, 2016

How to Send e Mail using PHPMailer and Gmail SMTP

hello friends after a long time i'm going to post a simple yet useful post here about SMTP mails, i received few email requests from my readers to post email verification feature in my login and registration tutorial i'll post email verification tutorial after this post this was first step to send emails from localhost and online server as well for that you have to use PHPMailer library, so take a quick a look at this tutorial to understand "how to send SMTP mails using PHPMailer"
How to Send e-Mail using PHPMailer and Gmail SMTP
Read more »

Saturday, May 21, 2016

How To Send An Email From A PHP Script With Attachments

PHP makes use of mail() function to send an email. This function requires three mandatory arguments that specify the recipients email address, the subject of the the message and the actual message additionally there are other two optional parameters.

mail( to, subject, message, headers, parameters );


Here is the description for each parameters.

Parameter Description
to  Specifies the receiver / receivers of the email
subject  Specifies the subject of the email. This parameter cannot contain any newline characters
message  Defines the message to be sent. Each line should be separated with a LF ( ). Lines should not exceed 70 characters

As soon as the mail function is called PHP will attempt to send the email then it will return true if successful or false if it is failed.

Multiple recipients can be specified as the first argument to the mail() function in a comma separated list.

Example

<?php
$to = "recipient@example.com";
$subject = "Hi!";
$body = "Hi, How are you?";
if (mail($to, $subject, $body)) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
?>


Thats it! Note that you can have PHP validate your email addresses for correctness before sending.


Sending Attachments - PHP Email Script

To send an email with mixed content requires to set Content-type header to multipart/mixed. Then text and attachment sections can be specified within boundaries.

A boundary is started with two hyphens followed by a unique number which can not appear in the message part of the email. A PHP function md5() is used to create a 32 digit hexadecimal number to create unique number. A final boundary denoting the emails final section must also end with two hyphens.

Attached files should be encoded with the base64_encode() function for safer transmission and are best split into chunks with the chunk_split() function. This adds inside the file at regular intervals, normally every 76 characters.

Following is the example which will send a file /php/phpmanual.txt as an attachment. you can code your program to receive an uploaded file and send it.
<?php
$to = "xyz@examplemail.com";
$subject = "This is subject";
$message = "This is test message.";
# Open a file
$file = fopen( "/php/phpmanual.txt", "r" );
if( $file == false )
{
echo "Error in opening file";
exit();
}
# Read the file into a variable
$size = filesize("/php/phpmanual.txt");
$content = fread( $file, $size);

# encode the data for safe transit
# and insert after every 76 chars.
$encoded_content = chunk_split( base64_encode($content));

# Get a random 32 bit number using time() as seed.
$num = md5( time() );

# Define the main headers.
$header = "From:xyz@examplemail.com ";
$header .= "MIME-Version: 1.0 ";
$header .= "Content-Type: multipart/mixed; ";
$header .= "boundary=$num ";
$header .= "--$num ";

# Define the message section
$header .= "Content-Type: text/plain ";
$header .= "Content-Transfer-Encoding:8bit ";
$header .= "$message ";
$header .= "--$num ";

# Define the attachment section
$header .= "Content-Type: multipart/mixed; ";
$header .= "name="phpmanual.txt" ";
$header .= "Content-Transfer-Encoding:base64 ";
$header .= "Content-Disposition:attachment; ";
$header .= "filename="phpmanual.txt" ";
$header .= "$encoded_content ";
$header .= "--$num--";

# Send email now
$retval = mail ( $to, $subject, "", $header );
if( $retval == true )
{
echo "Message sent successfully...";
}
else
{
echo "Error Sending Message...";
}
?>

 Thats all! You can implement this php script in your web page with some minor changes and you will be able to send emails using it.Isnt it interesting?

If you like this post then you can Subscribe to our blog to receive similar interesting updates directly in your email.You can use the Subscription Box below to subscribe to all our future updates for free.

Enjoy!

Tuesday, February 16, 2016

How to Send An Email in Gmail Internet Tips

The traditional letter writing using paper and pen is almost gone away where the touch of latest communicating way like internet is coming. Although the letter writing and sending in paperback is existed in some sectors such as government communicating purposes. But, for personal communicating, massive usage of email and other digital communication are noticeable.

However, if you dont know yet how to send an email, here are some quick tips to learn such process of sending an email.

This is a basic internet tips. The process is so simple and we are using the most prominent email service on the world named GMAIL. Gmail is a product of the most prominent search engine named Google. So, here we are going to show an email sending process using gmail. If you know that, that is enough to send an email.


Step-1: Firstly, go to this link. It is the log in page of gmail. To send an email in gmail, you are required to have an email account in gmail. You can create that by using that link too. If you have just log in there using your ID and password.


Step-2: After log in you will get the preference like above picture. Click on compose as like as the picture shown above.


Step-3: Look at the above picture. This is for your compose an email. In the box named "To", write the email address in where the written email will go. In the box named "Subject", write your email subject or title. You can leave it empty too. And the big box for writing is to write your message, idea, information which will be sent to other person. By putting one more email address, you can send an email to various person in one time. That means, to send same email to more than one person, you dont need to resend one email again and again. To send file such as picture, document, pdf file or anything else, you need to click on attach file and wait for uploading the file on your gmail. then you can click on "send". If you click on send, the email will reach to your destination email address within few seconds only!