top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to send email using php script?

0 votes
383 views
How to send email using php script?
posted Mar 13, 2017 by Kavyashree

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+2 votes

You have to use mail() function to send a mail.
mail($to,$subject,$message,$header);

The parameters used within mail function are
$to - Specifies the receiver / receivers of the email
$subject - Specifies the subject of a mail.
$message - Defines the message to be sent.
$header - Optional. Specifies additional headers, like From, Cc, and Bcc. The additional headers should be separated with a CRLF (\r\n)..

Example:

<?php
   $to = "somebody@example.com";
    $subject = "My subject";
    $txt = "Hello world!";
    $headers = "From: webmaster@example.com" . "\r\n" .`
    "CC: somebodyelse@example.com";
     mail($to,$subject,$txt,$headers);
 ?>
answer Mar 14, 2017 by Richa Patil
Similar Questions
0 votes

I'm using the class.phpmailer.php code to send email -- it works neat. I can send an email from my domain and it arrives almost immediately.

However, when I use the exact same code (except for the FROM address) from another domain I own, the email literally takes hours (up to 12) to arrive.

Any idea of why there is a difference of email transit times between the two domains?

+2 votes

Hi,

I am using phpMailer class to send the HTML email, but whenever I send the html email then at the receiving end we receive some special character (!) at random position.

We have set the charset as utf-8 and calling MsgHTML($body) to pass the body. Took an echo at the send function of phpMailer class where it is printing correctly but when looking at gmail or yahoo then we see some special characters.

MY Code

function qa_send_raw_email($charset, $fromemail, $fromname, $toemail, $toname, $subject, $body, $html, $smtp_active, $smtp_address, $smtp_port, $smtp_secure, $smtp_authenticate, $smtp_username, $smtp_password, $env=null)
{
    require_once 'php-mailer/class-phpmailer.php';

    $mailer=new PHPMailer();
    $mailer->CharSet=$charset;

    $mailer->From=$fromemail;
    $mailer->Sender=$fromemail;
    $mailer->FromName=$fromname;
    $mailer->AddAddress($toemail, $toname);
    $mailer->Subject=$subject;
    $mailer->Body=$body;

    if ($html)
        $mailer->IsHTML(true);

    if ($smtp_active) {
        $mailer->IsSMTP();
        $mailer->Host=$smtp_address;
        $mailer->Port=$smtp_port;

        if ($smtp_secure)
            $mailer->SMTPSecure=$smtp_secure;

        if ($smtp_authenticate) {
            $mailer->SMTPAuth=true;
            $mailer->Username=$smtp_username;
            $mailer->Password=$smtp_password;
        }
    }

    if ($env)
    {
        $mailer->SetFrom($fromemail, $fromname);
        $mailer->AddReplyTo($fromemail, $fromname);
    }

    return $mailer->Send();
}

Excepted Output

<p><strong>Test Data for php mailer.</strong><br\><br\>Thanks Madhu </p>

Current Output

<p><strong>Tes!t Data for php mailer.</strong><br\><br\>Thank!s Madh!u <! /p>

Any pointers.

Thanks,

0 votes

I have a dilemma I cant figure out how to send multiple files as an attachment to my email using python script. I can only send a single file attachment .

+4 votes

Question related to a internal company knowledge transfer site. Suppose there is a tag like PHP and I want to send mail to the PHP followers when a new question is posted in PHP tag?

Can i get any logic for it ?

+3 votes

How to send a mail using sendmail utility? Example would help?

...