PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label sendmail. Show all posts
Showing posts with label sendmail. Show all posts

Monday, July 18, 2022

[FIXED] What component to use to send mail with any kind of body?

 July 18, 2022     c#, document-body, email, sendmail     No comments   

Issue

I made a mail sender in C# but I'm having trouble with the body of the mail. It only sends the texts without pictures, links and other elements. Not to mention, I used RichTextBox for that purpose.

So now my question is: what component to use to send mail with pictures, links and else?

I also enabled IsBodyHtml to true.

What I want to do is to copy the pictures, links and texts (with different colors and size) from Microsoft Word and paste it to control, and when user gets mail he gets the exact same body and layout as I send them.


Solution

You'll need to send it as html. Save your word doc as html and use that. For the images in your document you can either point to them via their absolute urls (publicly available via the internet).

Or you could use the LinkedResource class.

With the LinkedResource class your images have to specify a cid in the source.

var inlineLogo = new LinkedResource("path/myfile.png");
                                inlineLogo.ContentId = Guid.NewGuid().ToString(); 

var imageHtmlFragment = string.Format("<img alt='My Logo'  src='cid:{0}' style='width: 250px;height: 60px;'/>",inlineLogo.ContentId);

var newMail = new MailMessage();

var view = AlternateView.CreateAlternateViewFromString(imageHtmlFragment, null, "text/html");
                        view.LinkedResources.Add(inlineLogo);
                        newMail.AlternateViews.Add(view);


Answered By - scartag
Answer Checked By - David Marino (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Tuesday, March 1, 2022

[FIXED] Codeigniter 3 Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method

 March 01, 2022     codeigniter, codeigniter-3, php, sendmail     No comments   

Issue

public function send_mail_verification(){
    $this->load->library('email');

    $config = array(
        'protocol'  => 'smtp',
        'smtp_host' => 'smtp.gmail.com',
        'smtp_port' => '587',
        'smtp_crypto' => 'tls',
        'smtp_user' => 'myacc@gmail.com',
        'smtp_pass' => 'mypass',
        'charset'   => 'iso-8859-1'
    );

    $this->email->initialize($config);

    $this->email->from('myemail3@gmail.com', 'Registration');
    $this->email->to('tosomeonemail@gmail.com');

    $this->email->subject('something');
    $this->email->message('Testing email.');

    if($this->email->send()){
        echo "success";
    }
    else{
        show_error($this->email->print_debugger());
    }
}

I've been looking at other solution that I find in the internet and none of them worked for me. I've also tried the mail function and changed some things in sendmail.ini and php.ini in xampp and that worked. However, the send mail configuration in codeigniter-3 is much better if I'm going to share my code to other so that they don't need to change some configuration in their sendmail.ini and php.ini. What do you think causes the error?


Solution

$this->email->set_newline("\r\n");

I added this one and it worked... wonder why.



Answered By - Amben Uchiha
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Monday, February 14, 2022

[FIXED] How do I get sendmail to work reliably on a Mac OS 10.5?

 February 14, 2022     macos, mamp, sendmail, sysadmin     No comments   

Issue

I need to use sendmail from Macs in an office. At the moment, I can get it to work on the two development Macs (which I think is due to MAMP being installed and working), but getting it to go on the others seems to be a problem...

I assume it's down to some config issue, and hope there's someway to fix it (without resorting to installing MAMP on each machine !).

I think it may be down to the 'local' nature of the from, but not sure. Here's a dump of /var/log/mail.log if that's any help:

Nov 14 14:37:06 claire-g5 postfix/master[5339]: daemon started -- version 2.4.3, configuration /etc/postfix
Nov 14 14:37:06 claire-g5 postfix/qmgr[5341]: 2B625250BDB: from=<claire@claire-g5.local>, size=1131, nrcpt=1 (queue active)
Nov 14 14:37:06 claire-g5 postfix/qmgr[5341]: D5D19250D5A: from=<claire@claire-g5.local>, size=1191, nrcpt=1 (queue active)
Nov 14 14:37:06 claire-g5 postfix/smtp[5344]: 2B625250BDB: host mx01.xxx.uk[212.x.x.134] said: 451 cannot relay now to <xx@xx.com>, please try again later (in reply to RCPT TO command)
Nov 14 14:37:06 claire-g5 postfix/smtp[5346]: D5D19250D5A: host mx01.xxx.uk[212.x.x.186] said: 451 cannot relay now to <xx@xx.com>, please try again later (in reply to RCPT TO command)
Nov 14 14:37:07 claire-g5 postfix/smtp[5346]: D5D19250D5A: to=<xx@xx.com>, relay=mx01.xxx.uk[212.x.x.134]:25, delay=2350, delays=2349/0.08/0.7/0.12, dsn=4.0.0, status=deferred (host mx01.xxx.uk[212.x.x.134] said: 451 cannot
Nov 14 14:37:07 claire-g5 postfix/pickup[5340]: 1A2EC2511D1: uid=501 from=<claire

Solution

Note that it's postfix that you have running on your mac, not sendmail.

The problem is that the machine mx01.xxx.uk[212.x.x.134] is configured to block mail relaying (accepting an email over SMTP and sending it on to the final mail server). The postfix configuration files are normally stored in /etc/postfix so you could start by looking there. In particular, look at the mynetworks setting in main.cf.



Answered By - Denis Hennessy
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Monday, January 10, 2022

[FIXED] How to send multiple settextbody yii2 send mail?

 January 10, 2022     php, sendmail, yii, yii-components, yii2     No comments   

Issue

Hi I've trying to make a form that can send email using yii/mail, the problem is I only can send one form to become text body, I've code the models like this:

     class CareerForm extends Model

    {

        public $name;

        public $email;

        public $subject;

        public $body;

        public $verifyCode;

        public $gender;

        public function rules()

        {

            return [

            [['name', 'email', 'subject', 'body','gender'], 'required'],

            ['email', 'email'],

            ['verifyCode', 'captcha'],

            ];

         }
         public function career($email)

         {

            if ($this->validate()) {

            Yii::$app->mailer->compose()

                ->setTo($email)

                ->setFrom([$this->email => $this->name])

                ->setSubject($this->subject)

                ->setTextBody($this->body)

                ->send();



            return true;

        }

        return false;

        }
    }

How can I use multiple parameters to

->setTextBody($this->body)

like

->setTextBody($this->body,$this->gender)

because in view I have several text input and radio list to send as an email, how can I do that?

My expectation on the text message will be like:

name
gender
variable 1
variable 2
variable n

SUMMARY edit = both answer is correct but I use

public function career($email)
{
    if ($this->validate()) {
        Yii::$app->mailer->compose('filename.html' ,[
            'email' => $this->email,
            'name' => $this->name,
             ])
            ->setTo($email)
            ->setFrom([$this->email => $this->name])
            ->setSubject('career')
            ->send();

        return true;
    }
    return false;}

Thanks for Ankur Garg and Pratik Karmakar


Solution

good practice to put you html in separate file and prepare mail body in that file

$body = $this->renderPartial('_mail_body.php' .[
                'gender' => $this->gender,
                'name' => $this->name,
    ]);

and the content _mail_body.php will be like this

<html>
<body>
<table cellpadding="0" cellspacing="0" align="center"  width="672px" style="font-size:24px; text-align:center;">
<tr>
    <td width="670px" align="center" style="border-left:1px solid #e0e0e0; border-right:1px solid #e0e0e0; font-size:24px; font-family:Arial, Helvetica, sans-serif; padding-top:47px;">
        <table width="608px" cellpadding="0" cellspacing="0" align="center">
            <tr>
                <td width="178px" style="font-family:Arial, Helvetica, sans-serif; font-size:14px; border-right:1px solid #e0e0e0; padding:11px;">
                    Name
                </td>
                <td width="427px" style="font-family:Arial, Helvetica, sans-serif; font-size:14px;padding:11px; color:#4e4e4e;">
                    <?php echo $name;?>
                </td>
            </tr>
            <tr>
                <td width="178px" style="font-family:Arial, Helvetica, sans-serif; font-size:14px; border-right:1px solid #e0e0e0; padding:11px;">
                    Gender
                </td>
                <td width="427px" style="font-family:Arial, Helvetica, sans-serif; font-size:14px;padding:11px; color:#4e4e4e;">
                    <?php echo $gender;?>
                </td>
            </tr>
        </table>
    </td>
</tr>
</table>
</body>
</html>


Answered By - Ankur Garg
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Tuesday, January 4, 2022

[FIXED] EC2 - Fresh PHP install - Mail not working

 January 04, 2022     amazon-ec2, lamp, php, sendmail     No comments   

Issue

I am getting familiar with Amazons EC2. I installed a LAMP setup but when I try to send emails through the mail() function that I have in my pages it does not work. I checked and sendmail is running and is on the phpinfo page.

I have tried changing the php.ini sendmail_from and it does nothing. SMTP port is open on the firewall... im freakin lost..


Solution

This won't directly solve your issue (edit: I mean the error message you have now edited out), but Amazon EC2 instances have a really spotty mail reputation. You're probably going to have deliverability issues.

Thankfully Amazon created the Simple Email Service to go along with EC2, with a free level of service for EC2 customers. The API is pretty simple and there are transport adapters for many excellent PHP mailing libraries, like SwiftMailer (transport).



Answered By - Charles
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Monday, January 3, 2022

[FIXED] Is anybody able to send mails to gmail through AWS LAMP server using postfix, sendmail

 January 03, 2022     amazon-web-services, lamp, php, postfix-mta, sendmail     No comments   

Issue

I am using php mail function to send mails to gmail,yahoo accounts. I have a AWS LAMP instance, i have installed postfix and sendmail. I went through many forums infinite number of forums, still not able to send mails. After too many changes i was able to see Message accepted for delivery, but after some time got the same message. stat=Deferred: Connection timed out with mta7.am0.yahoodns.net. stat=Deferred: Connection timed out with alt4.gmail-smtp-in.l.google.com.

Just i am wondering is anyone able to send mails using the same scenario.


Solution

TLDR: Sending email is hard. Don't attempt final delivery yourself. Use AWS SES or another ESP.

As AWS is aware that spammers have, and will, try to send their mail from anywhere by any means, AWS explicitly prevents EC2 Instances from being able to send email without some effort. It is not in your best interest as a sender to attempt to send email directly, unless you understand very well the various mechanisms in place to securely send email, accurately identify yourself as a legitimate sender, and gain reputation on your EIP with ISPs. Primarily, AWS intends for you to use SES to send email outside your VPC.

  • How to use Sendmail with SES
  • How to request port 25 unblocked

I can't emphasize enough that businesses small and large choose to send their mail through a third party (an ESP, or Email Service Provider, like AWS SES) in order to resolve the many, many issues that will come up when attempting to do it all yourself. The various acronyms involved, all of which require their own research and understanding from various RFC's include: SPF, DKIM, and DMARC; there is also the regular maintenance required in monitoring whether or not your IP is currently, or in the future, blacklisted by the various RBL's that monitor Spam Traps; and, of course, list hygiene, or scrubbing your list for bounces (not doing these is a guaranteed path to staying in the spam folder, even if you finally succeed in sending email out port 25). Let an ESP do some of this for you.



Answered By - Randy Wallace
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home
View mobile version

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing