私は自分のワードプレスサイトの1つでHTMLフォームを完成させました。送信されると、WP_Userデータベーステーブルにユーザーとしてユーザーが作成され、フォームからすべての情報を含むメールが送信されます。しかし、私のHTMLフォームでは、ユーザーは必要なファイルをアップロードできますが、電子メールにはファイル名のみが表示されます。私は実際のファイルを閲覧してダウンロードする方法を探しています。あなたはformタグでPHPでHTMLフォームからアップロードされたファイルを電子メールで送信
のenctypeプロパティセットをenctype="multipart/form-data"
を追加する必要が
<div id="container">
<form method="post" name="myForm">
<h1 align="center">Welcome!</h1>
<h2 align="center">Thank you for your interest. We look forward to working with you.</h2>
<h3>First Name</h3> <input type="text" name="fName" style="width: 355px;"/>
<h3>Last Name</h3> <input type="text" name="lName" style="width: 355px;"/>
<h3>Company Name</h3> <input type="text" name="compName" style="width: 355px;"/>
<h3>Business Needs</h3>
<select name="businessNeeds" style="width: 355px;">
<option value="">Select...</option>
<option value="IntDesign">Interior Designer</option>
<option value="Ecom">E-Commerce Only</option>
<option value="Retail">Retail Store Only</option>
<option value="RetailEcom">Retail and E-Commerce</option>
<option value="Mult">Multiple Locations</option>
</select>
<h3>Address</h3> <input type="text" name="address" style="width: 355px;"/>
<h3>City</h3> <input type="text" name="city" style="width: 355px;"/>
<h3>State</h3> <input type="text" name="state" style="width: 355px;"/>
<h3>Zip</h3> <input type="text" name="zip" style="width: 355px;"/>
<h3>Phone</h3> <input type="text" name="phone" style="width: 355px;"/>
<h3>Email</h3> <input id="email" type="text" name="uemail" style="width: 355px;"/>
<h3>Create a Username</h3> <input type="text" name="uname" style="width: 355px;"/>
<h3>Create a Password</h3> <input type="password" name="pass" style="width: 355px;"/>
<h3>Confirm Password</h3> <input type="password" name="ConfPass" style="width: 355px;"/>
<h3>Sales Tax ID</h3> <input type="text" name="taxID" style="width: 355px;"/>
<h3>Upload Tax ID Certificate</h3> <input type="file" name="fileUpload" style="width: 355px;"/>
<input type="submit" value="Submit" />
</form>
</div>
<?php
function create_account(){
$fName = (isset($_POST['fName']) ? $_POST['fName'] : '');
$lName = (isset($_POST['lName']) ? $_POST['lName'] : '');
$compName = (isset($_POST['compName']) ? $_POST['compName'] : '');
$businessNeeds = (isset($_POST['businessNeeds']) ? $_POST['businessNeeds'] : '');
$address = (isset($_POST['address']) ? $_POST['address'] : '');
$city = (isset($_POST['city']) ? $_POST['city'] : '');
$state = (isset($_POST['state']) ? $_POST['state'] : '');
$zip = (isset($_POST['zip']) ? $_POST['zip'] : '');
$phone = (isset($_POST['phone']) ? $_POST['phone'] : '');
$email = (isset($_POST['uemail']) ? $_POST['uemail'] : '');
$user = (isset($_POST['uname']) ? $_POST['uname'] : '');
$pass = (isset($_POST['upass']) ? $_POST['upass'] : '');
$ConfPass = (isset($_POST['ConfPass']) ? $_POST['ConfPass'] : '');
$taxID = (isset($_POST['taxID']) ? $_POST['taxID'] : '');
$fileUpload = (isset($_POST['fileUpload']) ? $_POST['fileUpload'] : '');
$email_from = 'admin';
$email_subject = "New Wholesale Form Submission";
$message = "You have received a new message from: \n";
$message .= "First Name: " .$_POST["fName"]. "\n";
$message .= "Last Name: ".$_POST["lName"]. "\n";
$message .= "Company Name: ".$_POST["compName"]. "\n";
$message .= "Business Type: " .$_POST["businessNeeds"]. "\n";
$message .= "Address: ".$_POST["address"]. "\n";
$message .= "City: ".$_POST["city"]. "\n";
$message .= "State: ".$_POST["state"]. "\n";
$message .= "Zip: ".$_POST["zip"]. "\n";
$message .= "Phone: ".$_POST["phone"]. "\n";
$message .= "Email: ".$_POST["uemail"]. "\n";
$message .= "Tax ID: ".$_POST["taxID"]. "\n";
$message .= "Certificate: ".$_POST["fileUpload"]. "\n";
$to = "email";
$headers = "From: $email_from \r\n";
if (!username_exists($user) && !email_exists($email)) {
$user_id = wp_create_user($user, $pass, $email);
if(!is_wp_error($user_id)) {
//user has been created
$user = new WP_User($user_id);
$user->set_role('subscriber');
wp_mail($to, $email_subject, $message, $headers);
//Redirect
wp_redirect('URL');
exit;
} else {
//$user_id is a WP_Error object. Manage the error
}
}
}
add_action('init','create_account');
?>
http://php.net/manual/en/features.file-upload.post-method.php –
https://developer.wordpress。 org/reference/functions/wp_mail /#comment-345 –