Email Attachments

16 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$99.99
List Price:  $139.99
You save:  $40
€92.72
List Price:  €129.81
You save:  €37.09
£79.26
List Price:  £110.97
You save:  £31.71
CA$135.49
List Price:  CA$189.69
You save:  CA$54.20
A$153.49
List Price:  A$214.89
You save:  A$61.40
S$134.92
List Price:  S$188.90
You save:  S$53.97
HK$782.50
List Price:  HK$1,095.53
You save:  HK$313.03
CHF 90.16
List Price:  CHF 126.23
You save:  CHF 36.07
NOK kr1,085.06
List Price:  NOK kr1,519.13
You save:  NOK kr434.06
DKK kr691.90
List Price:  DKK kr968.69
You save:  DKK kr276.78
NZ$167.41
List Price:  NZ$234.39
You save:  NZ$66.97
د.إ367.19
List Price:  د.إ514.08
You save:  د.إ146.89
৳10,980.73
List Price:  ৳15,373.46
You save:  ৳4,392.73
₹8,335.04
List Price:  ₹11,669.39
You save:  ₹3,334.35
RM472.40
List Price:  RM661.38
You save:  RM188.98
₦139,532.04
List Price:  ₦195,350.44
You save:  ₦55,818.40
₨27,813.53
List Price:  ₨38,940.06
You save:  ₨11,126.52
฿3,638.31
List Price:  ฿5,093.78
You save:  ฿1,455.47
₺3,237.16
List Price:  ₺4,532.16
You save:  ₺1,294.99
B$501.53
List Price:  B$702.17
You save:  B$200.63
R1,888.66
List Price:  R2,644.21
You save:  R755.54
Лв180.76
List Price:  Лв253.07
You save:  Лв72.31
₩134,741.70
List Price:  ₩188,643.77
You save:  ₩53,902.07
₪367.71
List Price:  ₪514.81
You save:  ₪147.10
₱5,617.33
List Price:  ₱7,864.49
You save:  ₱2,247.16
¥15,132.45
List Price:  ¥21,186.03
You save:  ¥6,053.58
MX$1,658.17
List Price:  MX$2,321.51
You save:  MX$663.33
QR364.88
List Price:  QR510.84
You save:  QR145.96
P1,378.06
List Price:  P1,929.34
You save:  P551.28
KSh13,256.67
List Price:  KSh18,559.87
You save:  KSh5,303.20
E£4,744.14
List Price:  E£6,641.99
You save:  E£1,897.84
ብር5,687.29
List Price:  ብር7,962.44
You save:  ብር2,275.14
Kz83,433.85
List Price:  Kz116,810.73
You save:  Kz33,376.88
CLP$98,290.17
List Price:  CLP$137,610.17
You save:  CLP$39,320
CN¥722.08
List Price:  CN¥1,010.95
You save:  CN¥288.86
RD$5,924.54
List Price:  RD$8,294.60
You save:  RD$2,370.05
DA13,479.97
List Price:  DA18,872.49
You save:  DA5,392.52
FJ$225.66
List Price:  FJ$315.94
You save:  FJ$90.27
Q780.13
List Price:  Q1,092.22
You save:  Q312.08
GY$20,949.30
List Price:  GY$29,329.86
You save:  GY$8,380.56
ISK kr13,941.60
List Price:  ISK kr19,518.80
You save:  ISK kr5,577.20
DH1,013.74
List Price:  DH1,419.27
You save:  DH405.53
L1,764.37
List Price:  L2,470.19
You save:  L705.82
ден5,702.11
List Price:  ден7,983.18
You save:  ден2,281.07
MOP$806.29
List Price:  MOP$1,128.85
You save:  MOP$322.55
N$1,909.24
List Price:  N$2,673.01
You save:  N$763.77
C$3,682.20
List Price:  C$5,155.22
You save:  C$1,473.02
रु13,347.49
List Price:  रु18,687.02
You save:  रु5,339.53
S/372.08
List Price:  S/520.93
You save:  S/148.85
K382.87
List Price:  K536.04
You save:  K153.16
SAR375.15
List Price:  SAR525.22
You save:  SAR150.07
ZK2,481.24
List Price:  ZK3,473.83
You save:  ZK992.59
L460.94
List Price:  L645.33
You save:  L184.39
Kč2,346.52
List Price:  Kč3,285.22
You save:  Kč938.70
Ft36,532.34
List Price:  Ft51,146.74
You save:  Ft14,614.40
SEK kr1,069.05
List Price:  SEK kr1,496.71
You save:  SEK kr427.66
ARS$85,802.56
List Price:  ARS$120,127.02
You save:  ARS$34,324.45
Bs691.35
List Price:  Bs967.92
You save:  Bs276.56
COP$386,901.39
List Price:  COP$541,677.43
You save:  COP$154,776.03
₡50,320.66
List Price:  ₡70,450.94
You save:  ₡20,130.27
L2,469.73
List Price:  L3,457.73
You save:  L987.99
₲739,686.52
List Price:  ₲1,035,590.72
You save:  ₲295,904.20
$U3,756.16
List Price:  $U5,258.77
You save:  $U1,502.61
zł399
List Price:  zł558.62
You save:  zł159.61
Already have an account? Log In

Transcript

Hello, in this video we are going to cover sending email attachments. So an email attachment can be anything like a PDF or an image. For example, I've got a PDF file next to my index file, right this dummy dot PDF, you literally just have some dummy text in this like one line of code, no matter what the contents are, you know, This tutorial will work exactly the same. So let's get started. So first of all, what we need to do is create a two variable and this is the email that I send in the message to so sonar systems, which I have open right here, and dollar from equals wherever it's coming from an office and make sure the domain is the same as the domain You know, have the website that the flower is running off. And we'll have a swarm name as well.

So it just makes it look a little better and we'll say some ink. And then what we're gonna do is have an email subject so So Jeff, and I going to pull up a bunch of new lines of easily scroll subject equals email attachment. Mail option. And now what we need to do is specify the file. So dollar file equals and for this, you just specify just the name but the location as long as it's in the same location. I just need to specify the name but if it was in a folder called no attachment, you do something different and it could be an online file.

Well, so Okay, there we go. No PDF NetFlow we need to do is actually do the, you know, the body of the website. So body equals and you know you can make it as complex as you want but I'm literally going to quick for a quick h1 tag in there and say I mean while at the floor from it, and now we're going to do is we need to create some headers. So this is where a lot of the code can be so he calls and say form and dollar from name. Then we're going to say dot and we're going to put angle bracket and Morgan Stanley is dot dawn All right. There we have space, dollar dot from dollar dollar and the hack.

Okay, so that'd be the name and then email address. Next all we need to do is create a mime boundary. This is just for you know separation of the tags and we'll just use empty phi function for this on the call it semi Rand equals MD five. Asked me based on time again, you can use something a bit more complex than this before we need this will be more than enough. Let me do a line boundary is going to be equal to multi part on the school boundary underscore x And then he put curly braces and we just put semi round. Excellent.

So, now what we need to do is add the headers for the attachment itself for dollar headers, dot equals for this backslash n mine dash version 1.0 backslash n dot con and toy with multi port backslash mixed semi colon backslash n and we need to just add the boundary. So boundary Nucor backslash and then we just put the curly braces and we'll just put dollar my Embry like so I'm missing something I am missing something so backslash. Yep. quotation quotation yep so that's indeed the flows or the quotation marks good which is what we need. We got the headers for the attachment we need to do a multi part boundary No. And also setting you know the character set for example.

Message equals dash dash, dollar mind boundary backslash n dot content type text slash HTML Shall sex equal, backslash UTF eight backslash quotation mark, backslash and quotation mark. There's quite a bit here. But once you've got this all set up, you can put this into a function if you want recommend doing now the next tab pointing to a class and learning more about it, but over the next few videos, we'll go over the PHP mailer anyway to the more advanced library external library, which is much better than using the built in function bonders show you the built in one as well. Okay, so let's say content transfer encoded seven bit. backslash n backslash n dot what's the variable cause hold on Finally, set a backslash n backslash n. quickly check if the file exists and this is also a good check to do a bit more optional but definitely recommended file if the greater than zero then we're going to check you know if the file that we've attached is a foil or the built in method for that is underscore foil.

Dollar file and in here, we are going to you know, start composing the message message dot equals That's the dollar mind boundary, backslash n dollar FP equals F open default opening the file for read permissions, and data equals F read. Then we're going to use the file I'm going to specify get, specify the file size, which we just easily do but this one the actual file itself and you'll always dynamically get the file sizes I have to constantly be checking that and it's not practical for you to be checking that it's online website. Then we just do f close the file. Now we need to do is All data equals shown in this course, base 64 in code validator and we just need to almost there now we've got close close here, message dot equals C to add some more, you know, content types onto here.

Okay, yeah. Content Type content type. Application for octet stream, semi Hold on. name equals backslash quotation mark. I see the back that she was escaping this. So it doesn't actually count.

Select and kill this tag as the purpose of if you were wondering what's going to put up they the dollar foil.so backslash backslash quotation mark, quotation mark backslash and quotation mark the abdus looking over to me, and yes either from simply close so far correctly. Content rich colons base dot base name dot a file dot backslash And we're going to number one again I know we've done quite a bit well we are almost there content dash disco this edition of Excel will provide all the source codes that you can literally just copy and paste their recommend still going through line by line, you know just over the code and figuring out why does but overall you can just copy and paste the file name equals backslash quotation mark, quotation mark, dub, base name dollar file dot backslash In the quotation mark here docx, file size Dola, file, dot, semi colon backslash and literally the last part of this append.

And then we'll say content trends include in base 64, Fs and backslash dollar data dot quotation mark. So backslash n backslash. Think we literally don't have your dot inside of here now, like we've got a couple more lines, but these are really small lines now. dot equals dash dash, curly brace, mine boundary, dash dash, dollar path equals dash F dot dollar and now we just send the email so dollar equals mail, dollar subject. Message headers don't turn past and now we just need to put the email states that CO is going to use a you know, inline if statement on what's called a conditional semi car. otherwise called, or we didn't email, question mark.

And if it's true, then we're going to say mail sent. And then if it's false, we'll say mail. And there we go. So we shall be able to run this. So Paige is not working unable to handle the requests on my shoulder. The internet is actually working and it's not some other issue.

The Internet seems to be working a joke. So okay, so that mean there must be some problem here. Let me just delete this. Okay, so that seems to be a Okay. What I'm going to do is delete this All of it just from here to the pot. There we go.

Okay, so something seemed like something inside of here is breaking it for some reason. An email sent but we're going to need the headers anyway so shouldn't work realistically. So in here there's something wrong. Honestly, it's probably something to do with this. No actually probably not. That should be not Fred there should be f read uncomfortable.

So mildly sand and Okay, so as the one minutes ago, okay, so that's the one that, you know, didn't have all the code in there. Hence why there has messed up. But this one has successfully sent, and it's got the PDF data all there was to it. So yeah, that's how you send an attachment. One thing that I wanted to mention is the first time I tested this, it took about 15 minutes for the attachment to come through. So just be patient, and you don't get any errors.

And you know, you can use the code from the GitHub page, be patient you know, also wait up to an hour to do the first time that that mouse I was connecting to, you know, particular mouse over that you might get a bit of a delay. Apart from that you should be all good to go for email attachments using the mail function. If you have any questions, feel free to pop me a message. And as usual, I look forward to seeing you in the next video.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.